简体   繁体   中英

Rails Nested N+1 Query Issue

My Associations are like this:

vendor has shipments  
shipment has order
order has products

In My controller I have written as

@shipments = @vendor.shipments.includes(:order)

But in my view I am using like

shipment.order.products.collect(&:name)

So it is returning N+1 Query issue by Rails 'bullet' gem

Anyone Help me to resolve this problem of Nested N+1 Query Issue? How I need to write in the controller?

@shipments = @vendor.shipments.includes(:order => :products)

should work. Read more about it here http://guides.rubyonrails.org/active_record_querying.html#nested-associations-hash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM