All threads / Eager Loading on Rails 5.1

Ask A Question


You’re not receiving notifications from this thread.

Eager Loading on Rails 5.1

Pardha asked in Rails

Hi all,

Seems that the eager loding doen't work in my application.  Please let me  know whether  I need to enable or configure anything.  Here is th code for association mappings. 
 class Event < ApplicationRecord
                has_many :receipts, dependent: :destroy
                has_many :receipt_happenings, through: :receipts
                has_many :receipt_amounts, through: :receipt_happenings, source: :paper_money

I could see that the query is running while Iteraing the result set coming from

Event.includes(receipts: {receipt_happenings: :paper_money})

What's the issue you're facing? Is that you're noticing N+1 queries when you loop over events? Or something else?

Yes Jeffrey . I am noticing N+1 queries when loop over events.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 52,026+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.