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
Preloading all ancestors #395
Comments
I've found I let this issue open in case you want to add something inside the gem to help users do that even more easily. Maybe a class method
and a scope like :
Would you consider a PR to add these 2 snippets ? |
Great job, thank you!
Google did not help me, so I made it in batches:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi folks,
At solidusio/solidus#3004, we have a use case for which I can't find a good solution and I would like your advices.
We have many taxonomies, and each taxonomy is a nested set of taxons.
Taxons can be any depth level so they have ancestors.
We have an API endpoint where the user can ask for multiple taxons at once and we generate a "pretty name" for each one in the form of
Ancestor3 > Ancestor2 > Ancestor1 > LeafTaxon
.To do that, we use the
ancestors
method, but it generates a new SQL query for each taxon the user asked to retrieve : a typical N+1 problem :/What I would like to do would be to
includes(:ancestors)
but it's not defined as anhas_many
and thus don't work.Do you have any tips on how to preload all ancestors of multiple taxons with the minimum amount of SQL queries ?
The text was updated successfully, but these errors were encountered: