Rails Nested N+1 Query Issue

ruby-on-rails

Solution

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

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

Problem

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?

Original source