4

I have a class inquiry_process that has_one inquiry, in my specs I have the following

let(:serializer) { described_class.new(inquiry_process, options) }
let(:options) do
  {
    include: %i[inquiry company assignee banks]
  }
end

Then I create a inquiry for inquiry_process

let(:inquiry) { build :inquiry, company: company, details: details, creator: creator }

And when I create the inquiry_process I am getting the following

 Bullet::Notification::UnoptimizedQueryError:
     
    USE eager loading detected
      Inquiry => [:partner_application]
      Add to your finder: :includes => [:partner_application]
    Call stack

How can I fix this

max
  • 96,212
  • 14
  • 104
  • 165
  • 1
    I think what bullet is telling you is that you should be including/eager loading when you load `inquiry_process` (or wahtever it is that you are serializing). `include` just tells AMS to also serialize the assocations and will create multiple n+1 queries unless you have loaded the association. – max Nov 04 '21 at 16:56
  • 1
    However this won't really work when you use `build` instead of `create` from FactoryBot/FactoryGirl as the record is not actually persisted in the database. If you want to use `build` you would need to stub out the assocations. – max Nov 04 '21 at 17:00

0 Answers0