Can't avoid under/overfetching
What were you trying to do?
I added bullet to my project, which shows that I should add eager loading for my dashboard relationships to avoid N+1 queries when showing the index. For instance I have a Course
with program: Field::BelongsTo
, and this program
is visible on the course index.
Bullet throws:
Bullet::Notification::UnoptimizedQueryError: user: sdubois
GET /admin/courses
USE eager loading detected
Program => [:translations]
Add to your query: .includes([:translations])
The issue is gone if I remove program
from the Course's COLLECTION_ATTRIBUTES
.
So following the documentation, I changed program:
to Field::BelongsTo.with_options(scope: -> { Program.eager_load(:translations) })
.
What did you end up with (logs, or, even better, example apps are great!)?
The option has no effect. In fact even if I change to Field::BelongsTo.with_options(scope: -> { raise "I got called!" })
, it does not raise. It seems that this scope
option is not applied.
What versions are you running?
- Rails 6.0.3.2
- administrate 0.14.0