Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Eager Loading on Rails 5.1

Rails • Asked by Pardha

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.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.