[英]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.