我正在努力如何找到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
答案 0 :(得分:0)
我相信'基础'是您正在寻找的方法!
class Something
field :some_field
has_many :whatevers, do
def my_extension_method
klass # Something
base # #<Something _id="..." >
end
end
end