0

我觉得我说的很对...

我有一个名为资产的模型,它是多态的:

class Asset < ActiveRecord::Base
  belongs_to :assetable, :polymorphic => true
...
end

我有一个充当范围的类级别方法:

def self.some_scope
     assets = Asset.joins(:assetable).where('assetable.approved_at IS NOT NULL').order('assetable.approved_at DESC').limit(50)
end

我正在尝试获取其父approved_at属性不为空的资产列表,并按该approved_at属性按降序排列,限制为 50。我承认我不确定我所拥有的与正确性有多接近,但我现在得到的错误是:

"Can not eagerly load the polymorphic association :assetable"
4

1 回答 1

0

做到这一点的正确方法是以不同的方式思考它,例如:

# If assetable model is called Folder
def self.some_scope
   folders = Folder.where('approved_at IS NOT NULL').order('approved_at DESC').limit(50)
   folders.collect{|p| p.assets}
end
于 2010-09-01T17:31:08.573 回答