0

includes用来避免 N+1 查询。但是,我在嵌套元素中使用 Mobility。这是我尝试过的,但我收到一个错误:undefined method 'i18n' for #<ActiveRecord::AssociationRelation [#<FeedItem 或者如果我从查询中Can't join 'FeedItem' to association named 'string_translations'; perhaps you misspelled it?删除。i18n

current_user.feed_items.includes(:post).i18n.eager_load(:string_translations)

使用 ActiveRecord 包含时,在嵌套元素上使用 Mobility 的 eager_load 的正确方法是什么?

class User < ApplicationRecord
  has_many :feed_items, dependent: :destroy
  has_many :feed_posts, through: :feed_items, class_name: 'Post', source: :post
end
class FeedItem < ApplicationRecord
  belongs_to :post
  belongs_to :user
end
4

0 回答 0