Mongoid协会扩展代理所有者

时间:2013-07-16 20:39:57

标签: ruby-on-rails mongoid

我正在努力如何找到Mongoid中的扩展协会所有者。 AFAIK是ActiveRecords中的proxy_association.owner。

class Something
  field :some_field

  has_many :whatevers, extend: ExtraStuff
end

module ExtraStuff
  def recent
    # I need "some_field" here, but there's no "proxy_association"
  end
end

1 个答案:

答案 0 :(得分:0)

我相信'基础'是您正在寻找的方法!

class Something
  field :some_field

  has_many :whatevers, do
      def my_extension_method
        klass # Something
        base  # #<Something _id="..." >
      end
  end
end

仅供参考:https://github.com/mongoid/mongoid/issues/3171