【发布时间】:2015-10-11 14:09:14
【问题描述】:
我有一个 Has-Many:Through 关联,其中一侧 (AccessLevel ) 是定义的模型 'AccessLevel' ,但另一侧可以设置多个资源
我定义了要包含在这些模型中的特定关注点,并尝试使用多态关联
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
这是一个正确的实现还是我会提出一些意想不到的附带问题?
感谢反馈
【问题讨论】:
标签: ruby-on-rails-4 activerecord polymorphic-associations