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

False positive when ActiveRecord::Associations::Preloader is used #704

Open
EnotPoloskun opened this issue Apr 1, 2024 · 0 comments
Open

Comments

@EnotPoloskun
Copy link

EnotPoloskun commented Apr 1, 2024

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

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

No branches or pull requests

1 participant