Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many-to-one (and one-to-one) join #3337

Draft
wants to merge 15 commits into
base: 4.12.x
Choose a base branch
from
Draft

Conversation

radovanradic
Copy link
Contributor

This might be the fix for issue. The idea is not SELECT entity id for many-to-one and one-to-one relation and only SELECT entity and its fields if joined.
However, it does change previous behavior and does not select entities with just id for many-to-one, one-to-one, which I think is correct way and fixes original issue).

@radovanradic radovanradic requested a review from dstepanov March 3, 2025 14:23
@@ -92,7 +92,7 @@ class CriteriaSpec extends AbstractCriteriaSpec {
String query = getSqlQuery(criteriaQuery)

expect:
query == '''SELECT book_."id",book_."author_id",book_."title",book_."total_pages",book_."last_updated" FROM "book" book_ WHERE (book_."id" IN (SELECT book_book_."id" FROM "book" book_book_ WHERE (book_book_."id" = 123)))'''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not return field from the association if not requested by join for retrieval

@@ -524,7 +524,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
when:
def updateReturningCustomMethod = repository.findPossibleMethods("updateReturning").findFirst().get()
then:
getQuery(updateReturningCustomMethod) == 'UPDATE "book" SET "author_id"=?,"genre_id"=?,"title"=?,"total_pages"=?,"publisher_id"=?,"last_updated"=? WHERE ("id" = ?) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning also returns only fields belonging to the entity. This might be the most significant change, not sure if returning could have @Join annotation to tell Micronaut Data to return joined entities?

@radovanradic radovanradic changed the title Fix many-to-one (and one-to-one_ join Fix many-to-one (and one-to-one) join Mar 3, 2025
@radovanradic radovanradic changed the base branch from 4.11.x to 4.12.x March 17, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants