如何在 ActiveRecord 中按多态模型的父级属性进行排序?
我认为我的措辞正确...
我有一个名为 asset 的模型,它是多态的:
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"
I think I worded that correctly...
I have a model called asset which is polymorphic:
class Asset < ActiveRecord::Base
belongs_to :assetable, :polymorphic => true
...
end
I have a class level method that acts as a scope:
def self.some_scope
assets = Asset.joins(:assetable).where('assetable.approved_at IS NOT NULL').order('assetable.approved_at DESC').limit(50)
end
I am trying to get a list of assets who's parent's approved_at
attribute is not null and order by that approved_at
attribute in descending order with a limit of 50. I'll admit that I'm not sure how close what I have is to being correct but the error I am getting now is:
"Can not eagerly load the polymorphic association :assetable"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做到这一点的正确方法是以不同的方式思考它,例如:
The proper way to do this is to think of it differently like: