2011-12-09 169 views
0

我有以下型號:雙向polymophic關係

class Infoset < ActiveRecord::Base 
    belongs_to :infosetable, :polymorphic => true 
end 

class Product < ActiveRecord::Base 
    belongs_to :productset 
    has_one :infoset, :as => :infosetable, :dependent => :destroy 
end 

class Productset < ActiveRecord::Base 
    has_one :infoset, :as => :infosetable, :dependent => :destroy 
    has_many :products 
end 

我可以通過Product.infosetProductset.infoset

信息集細,但我怎麼得到通過InfosetProductProductset

infoset.product只是返回信息。

回答

3

@infoset.infosetable將根據情況返回產品或產品組。

+0

我剛剛得到method_missing,當我嘗試。 –

+0

等等...我想我有一個愚蠢的攻擊。試了一遍,它似乎工作.. –

+0

我試圖打電話infosetable集合。 DERP。 'infoset = Infoset.where(:usp_sku => params [:usp_sku])infoset.infosetable' –