0

I'm using includes to avoid N+1 queries. However, I'm using Mobility in nested elements. This is what I've tried, but I'm getting an error: undefined method 'i18n' for #<ActiveRecord::AssociationRelation [#<FeedItem or Can't join 'FeedItem' to association named 'string_translations'; perhaps you misspelled it? if I drop i18n from the query.

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

What is the proper way of using Mobility's eager_load on nested elements when using ActiveRecord includes?

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
Dan
  • 1,274
  • 2
  • 15
  • 32

0 Answers0