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

Advise users on skipping lazy loaded associations #998

Open
gjtorikian opened this issue Sep 1, 2022 · 1 comment
Open

Advise users on skipping lazy loaded associations #998

gjtorikian opened this issue Sep 1, 2022 · 1 comment
Labels

Comments

@gjtorikian
Copy link

👋 Modern Rails (> 6) now support ways for automatically detecting N+1 queries: https://dev.to/junko911/rails-n-1-queries-and-eager-loading-10eh

Without considering this, you may get errors like this in your app:

ActiveRecord::StrictLoadingViolationError: `Organization` is marked for strict_loading. The FriendlyId::Slug association named `:slugs` cannot be lazily loaded.
/Users/gjtorikian/Development/yettoapp/yetto/db/seeds.rb:15:in `<main>'

I decided for my app this was an okay performance "hit" (read: I didn't want to figure out how to fix it). It would be good to advise users that they can add the following to their model to disable the check on any calls to the slugs has_many association:

reflections["slugs"].options[:strict_loading] = false
@parndt parndt added the pinned label Nov 15, 2022
@aejohnmartin
Copy link

Does anyone have advice on how to eager load the slugs association?

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

No branches or pull requests

3 participants