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

Fixes #91. Applies scopes to eager-loaded associations when they are nested. #92

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

asedge
Copy link
Collaborator

@asedge asedge commented Mar 22, 2024

I have previously fixed the eager loading of scoped associations (#67). The way the query was built when using includes with association nesting is different so it only worked if you didn't try to nest anything above it (e.g. includes(:scoped_association) and not includes(scoped_association: :child). I did a bit of a refactor to align them so the latter example will now work and because it's called recursively the scopes will be applied all the way down the chain.

SELECT Id, Name, Link__c,
(SELECT Id, Title__c, BlogId, IsActive,
(SELECT Id, PostId, PosterId__c, FancyPostId, Body__c
FROM Comments__r WHERE (1 = 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

WHERE (1 = 0)) nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😄 it was one of the pre-defined scopes from the original authors

Copy link
Contributor

@bfrey08 bfrey08 left a comment

Choose a reason for hiding this comment

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

Makes sense, good stuff!

Copy link
Contributor

@swpreethi swpreethi left a comment

Choose a reason for hiding this comment

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

I like how you refactored the existing projection builder and re-used it in the nested projection builder thereby keeping it all to be from one place.
Great stuff !! This would help us use the nested includes more effectively . thanks 😄

@asedge asedge merged commit 7551972 into main Mar 26, 2024
5 checks passed
@asedge asedge deleted the apply_association_scopes_on_nested_includes branch March 26, 2024 19:43
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.

3 participants