我有一個多態關聯像這樣 -查詢多態關聯
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 ])
這使得「不能急於加載多態關聯:可認可的「錯誤
如何正確地給出條件,以便獲得可批准項目未被刪除的批准結果集?
感謝所有幫助提前
代替N + 1,這可能是與4個散裝查詢,一個用於每個關聯類加在所有關聯的初始準備掃描來完成。準備數據結構可以是將每個關聯類映射到[source_id,association_id]的哈希。 – mahemoff 2015-04-21 09:01:07