我有这样的多态性关联-

class Image < ActiveRecord::Base
  has_one :approval, :as => :approvable
end

class Page < ActiveRecord::Base
  has_one :approval, :as => :approvable
end

class Site < ActiveRecord::Base
  has_one :approval, :as => :approvable
end

class Approval < ActiveRecord::Base
  belongs_to :approvable, :polymorphic => true
end

我需要在approval.apporvable.deleted = false
我试过这样的东西-
@approvals = Approval.find(:all,
   :include => [:approvable],
   :conditions => [":approvable.deleted = ?", false ])

这就产生了“不能急切地加载多态关联:approvable”错误
如何正确地给出条件,以便我得到一个带有批准的结果集谁的可批准项不会被删除?
谢谢你的帮助

最佳答案

这是不可能的,因为所有“approvable”都位于不同的表中。相反,您必须获取所有批准,然后使用普通数组方法。

@approvals = Approval.all.select { |approval| !approval.approvable.deleted? }

09-06 23:01