【发布时间】:2017-12-04 21:26:17
【问题描述】:
我正在使用 Bullet gem 来查看我的应用程序中有 n+1 个查询的位置。它告诉我在调用我的序列化程序时渴望加载我的关联taggings。我的代码如下所示:
render json: @products, each_serializer: ::V1::ProductSerializer, includes: [:taggings], links: links, status: :ok
但是在我添加之后,我仍然收到来自 Bullet gem 的相同警告。看起来像这样:
GET /api/v1/product_feed?state=CA&page=1
USE eager loading detected
Product => [:taggings]
Add to your finder: :includes => [:taggings]
Call stack
/home/jay/current_projects/api/app/controllers/api/v1/products_controller.rb:111:in `product_feed'
有谁知道为什么标签表没有被急切加载。
【问题讨论】:
标签: ruby-on-rails ruby eager-loading active-model-serializers