现在的位置: 首页 > 综合 > 正文

source,through

2018年09月10日 ⁄ 综合 ⁄ 共 666字 ⁄ 字号 评论关闭

module ActivityMethods
    def self.included(base)
      base.send :include, InstanceMethods
      base.has_many :activity_memberships
      base.has_many :members, :through => :activity_memberships, :source => :user
    end

end

:source
Specifies the source association name used by has_many :through queries. Only use it if the name cannot be inferred from the association. has_many :subscribers, :through => :subscriptions will look for either :subscribers or :subscriber on Subscription, unless
a :source is given.

:source 指定has_many :through查询的源关联名。 只有在关联名和所要关联的类名不相关的时候才需要用到. 如果没有指定:source,那么has_many :subscribers, :through => :subscriptions会去查找subscription上边的:subscribers或者:subscriber关联,假设设置了:source => :user,则会去查找:subscription上的:user关联

抱歉!评论已关闭.