bullet icon indicating copy to clipboard operation
bullet copied to clipboard

[Question] How to includes to dependent destroy

Open Piioo opened this issue 2 years ago • 0 comments

We have a model like this

class Consumer < ApplicationRecord
  has_many :offers, dependent: :destroy
end 

class Offer < ApplicationRecord
  has_many :incidents, dependent: :destroy
end

When we try to destroy the consumer with consumer.destory! we get this unexpected error

Minitest::UnexpectedError:
       Bullet::Notification::UnoptimizedQueryError: user: pisz
       DELETE /consumers/b900b64f-1f30-4694-980f-4bbc029b5c10/delete
       USE eager loading detected
         Offer => [:incidents]
         Add to your query: .includes([:incidents])

How I may add includes to offer.incidents?

Piioo avatar Jul 28 '22 09:07 Piioo