Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Apply scoped_as option when eager loading associations #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Apply scoped_as option when eager loading associations #102

wants to merge 2 commits into from

Conversation

bradstewart
Copy link
Contributor

The :scoped_as options on HasManyAssociations wasn't being applied when eager loading with :includes, so I took a quick stab at fixing it.

I wasn't entirely sure when ActiveQuery should be used as opposed to Query, so let me know if these changes might cause any unintended problems. I will update the specs soon if you like these changes.

query.instance_exec &scope
end
end
apply_scope query
Copy link
Contributor

Choose a reason for hiding this comment

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

This is within a define_method block, which is adding to the API of @parent. I don't think you will have access to apply_scope when the dynamically defined method is invoked.

@DanOlson
Copy link
Contributor

@bradstewart can we start with a failing test that reproduces your problem? I think I've seen what you're describing before, so I'm certainly interested in finding the root cause.

@bradstewart
Copy link
Contributor Author

@DanOlson Yep you were right, sorry about that. I wasn't paying attention when I quickly made that method. Will figure out a better way to reuse the code at some point.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants