Skip to content

Commit

Permalink
fix NPlusOneQuery.call_association in AR4 empty? hack
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Nov 5, 2023
1 parent 6beb6cb commit 2282b01
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/bullet/active_record4.rb
Expand Up @@ -147,7 +147,9 @@ def empty?
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
alias_method :origin_empty?, :empty?
def empty?
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !loaded?
if Bullet.start? && !has_cached_counter?(@reflection)
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
end
origin_empty?
end
end
Expand Down

0 comments on commit 2282b01

Please sign in to comment.