bullet icon indicating copy to clipboard operation
bullet copied to clipboard

Bullet not detecting HABTM classes correctly (buggy regex?)

Open ChenoChosencar opened this issue 6 years ago • 1 comments

I am upgrading from Rails 4.2 to Rails 5.0.5, and from Bullet 5.4.2 to Bullet 5.6.1 I have a Foo class with a HABTM relationship with Bar, but am running into the following UnoptimizedQueryError:

class Foo < ActiveRecord::Base
  has_and_belongs_to_many :bars, join_table: :bars_foos
  ...
end
class Bar < ActiveRecord::Base
  has_and_belongs_to_many :foos, join_table: :bars_foos
  ...
end
Bullet::Notification::UnoptimizedQueryError:
PUT /some_endpoint/24
USE eager loading detected
Foo::HABTM_Bars=> [:bars]
Add to your finder: :includes => [:bars]

It seems like HABTM classes should be filtered out, and this regex looks like it doesn't catch this subclass case: https://github.com/flyerhzm/bullet/blob/master/lib/bullet/active_record5.rb#L50 I can work around this by adding an exception to the whitelist, but is this a known issue?

ChenoChosencar avatar Oct 30 '17 23:10 ChenoChosencar

You can still eager load HABTM relations. This should not be filtered out:

Foo.includes(:bars).

SleeplessByte avatar Feb 19 '18 00:02 SleeplessByte