我有以下3種型號:多態查詢包含所有的多態記錄
class One < ActiveRecord::Base
has_many :locations, as: :locatable, dependent: :destroy
has_many :countries, through: :locations, order: :name
end
class Two < ActiveRecord::Base
has_many :locations, as: :locatable, dependent: :destroy
has_many :countries, through: :locations, order: :name
end
class Three < ActiveRecord::Base
has_many :locations, as: :locatable, dependent: :destroy
has_many :countries, through: :locations, order: :name
end
如何建立一個包含所有三個型號的所有記錄的ActiveRecordRelation?
你能拼出來的僞代碼你想要的查詢指定?如果你只想要所有這些,只需做一個* .all並將結果添加到結果數組中。 – timpone
@timpone問題的關鍵是我想要一個ActiveRecordRelation,而不是一個數組。 – Undistraction
你嘗試過繼承嗎?第二類<然後是第三類<兩個 –