False positive when `ActiveRecord::Associations::Preloader` is used
EnotPoloskun opened this issue · comments
Pavel commented
I have before_action
method which checks if profile of current user is enabled
before_action :require_enabled_profile
....
def require_enabled_profile
unless current_user.profile.enabled?
...
end
end
...
def current_user
@current_user ||= super.tap do |user|
ActiveRecord::Associations::Preloader.new(
records: [user],
associations: [:profile],
).call
end
end
and I am still getting error
USE eager loading detected
User => [:profile]
Add to your query: .includes([:profile])
in my require_enabled_profile
method.
I double checked that current_user.association(:profile).loaded?
returns true in require_enabled_profile
method(before unless
). And enabled?
method of profile
does no any queries and just returns true or false.
Does it mean that bullet
will indicate association loading as n+1
even if such associations were preloaded via ActiveRecord::Associations::Preloader.
?
Bullet version: 7.1.6
Rails version: 7.0.8