2015-10-11 37 views
0

我有一個過很多:通過聯想,在其一側(ACCESSLEVEL)是定義模式「ACCESSLEVEL」,但對方可以爲多個資源軌道4 - 關聯 - 是否有可能在一個多方關聯的多邊形關聯?

設置我定義了一個特定的關注納入這些模型,並試圖用多態關聯

class AccessLevel < ActiveRecord::Base 
     has_many :allowed_activities 
     has_many :actionable, through: :allowed_activities  
    end 

    class AllowedActivity < ActiveRecord::Base 
     belongs_to :access_level 
     belongs_to :actionable, polymorphic: true 
    end 


    class <Model> < ActiveRecord::Base 
     include Authorizable 
    end 

    module Authorizable 
     extend ActiveSupport::Concern 
     included do 
     has_many :allowed_activities, as: :actionable 
     has_many :access_levels, through: :allowed_activities 
     end 
    end 

是一個正確的實現還是我將提出一些意想不到的問題,抵押物?

感謝反饋

回答

0

這是不可能使用的has_many:多態對象

通過我需要指定每個對象(表,的SOURCE_TYPE ...

has_many :actionable_sheets, :through => :allowed_activities, :source => :actionable, :source_type => 'Sheet'