1

我正在努力如何在 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
4

1 回答 1

0

I believe that 'base' is the method you are looking for!

class Something
  field :some_field

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

Just for reference: https://github.com/mongoid/mongoid/issues/3171

于 2013-11-21T19:50:00.100 回答