2011-12-09 19 views
0

I持って次のモデル:双方向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

微細なビアインフォセットを得ることができますしかし、どのように私はProductまたはProductsetInfosetを経由して入手できますか?

infoset.productは、単に情報セットを返します。

答えて

3

@infoset.infosetableは、必要に応じて製品または製品セットのいずれかを返します。

+0

私はそれを試みるときにちょうどmethod_missingを取得します。 –

+0

待って...私は愚かな攻撃をしていると思う。もう一度試してみるとうまくいったようです。 –

+0

私はコレクションのinfosetableを呼び出そうとしていました。 Derp。 'infoset = Infoset.where(:usp_sku => params [:usp_sku])infoset.infosetable' –