[英]Rails Nested N+1 Query Issue
我的協會是這樣的:
vendor has shipments
shipment has order
order has products
在我的控制器中,我寫了
@shipments = @vendor.shipments.includes(:order)
但在我看來,我正在使用
shipment.order.products.collect(&:name)
所以它正在返回Rails'bullet'gem的N + 1 Query問題
任何人幫我解決嵌套N + 1查詢問題? 我怎么需要在控制器中寫?
@shipments = @vendor.shipments.includes(:order => :products)
應該管用。 在這里閱讀更多相關信息http://guides.rubyonrails.org/active_record_querying.html#nested-associations-hash
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.