class Person
include Mongoid::Document
field :name
embeds_many :addresses
end
class Company
include Mongoid::Document
field :name
embeds_many :addresses
end
class Address
include Mongoid::Document
embedded_in :addressable, inverse_of :addresses
end
我想是这样的嵌入在许多文件
company = Company.first
person = Person.first
address = Address.new
company.addresses << address
company.save
=>true
person.addresses << address
person.save
=>true
但我没有发现地址嵌入person.But我发现它 嵌入公司。 有没有人知道为什么?或者我不能在多个文档中嵌入地址。
再次当我扭转这样
person.addresses << address
person.save
=>true
company.addresses << address
company.save
=>true
我发现地址是嵌入在人不在公司.. 任何想法。
感谢的快速反应。当我尝试Person.find(person_id).addresses它给了我地址。但是,在克隆地址对象之后尝试使用Company.find(company_id).addresses时,它并没有给我地址。当只做Person.find(person_id).addresses.first.addressable时,我应该获取人员和公司对象。有什么解决方案吗? – kriysna 2010-08-13 03:03:37