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.


Is this solved ?

Join the discussion
Create an account Log in

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

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

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