norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.13k stars 589 forks source link

Advise users on skipping lazy loaded associations #998

Open gjtorikian opened 2 years ago

gjtorikian commented 2 years ago

đź‘‹ 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
aejohnmartin commented 4 months ago

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