-
Notifications
You must be signed in to change notification settings - Fork 223
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
with and many-to-many generates n+1 queries #371
Comments
Yes, Korma fetches relations lazily for each entity so this is n+1 queries. You should be able to avoid it by using |
I used join but the returned map is really hard to understand:
I ended up with two queries, much similar to the way you handle has_many relations. |
Yes, I am not sure what you mean by "the way Korma handles has-many relations". Has-many generates n+1 queries as well but without join table. |
There is a with-batch directive which allows you to fetch with two queries instead of n+1 but it only applies to has-many relations. |
See here: Line 931 in 5bb4e63
|
Right. I am not sure why it hasn't been implemented for many-to-many. PR welcome :) |
I guess similar problem is also meant in this issue: korma/korma.incubator#7 |
A PR addressing this issue would be welcome. I'm closing older tickets. Is this still a priority? If there hasn't been a response to this issue in 2 weeks, I'll close the ticket. |
I believe it is still relevant. |
We have a many to many connection between users and accounts
There is a join table of users_accounts
When we
(select users (with accounts))
:This is the dry-run result:
We only see here one of the second query but in reality the second query repeats for each user.
Isn't this N+1 queries? Is there a way to avoid it?
The text was updated successfully, but these errors were encountered: