-
Notifications
You must be signed in to change notification settings - Fork 124
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
[Suggestion] Add support for eager loading optionally #138
Comments
Can you explain how that would be used and why? |
Hello @rafaelfranca E.g. users = User.find([ 1, 2 ]) # This generates a query SELECT * FROM users WHERE id IN (1, 2)
users.first.posts # This generates a query SELECT * FROM posts WHERE user_id = 1
users.first.posts # This generates a query SELECT * FROM posts WHERE user_id = 1 again. In the other hand: users = User.includes(:posts).find([ 1, 2 ]) # This generates both queries (SELECT * FROM users WHERE id IN (1, 2)) and (SELECT * FROM posts WHERE user_id IN (1, 2))
users.first.posts # No query
users.last.posts # No query If we had this feature here, we could do something like I know that can be done with a custom Locator (which I already did for my case) but I thought that having that option could be useful to anyone as it is very generic. |
Makes sense. Do you want to open a PR for it? |
Sure. Thanks! @rafaelfranca |
Hello. I would like to ask you if there is an specific reason why not to optionally allow eager load of relationships on locate/locate_many.
I mean something like this:
It would be not exactly like that code, but well, it's an idea.
Thanks in advance
The text was updated successfully, but these errors were encountered: