Mongoid:如何将嵌入对象存储在不同的容器中(如store_in)

时间:2011-11-08 11:49:14

标签: mongodb mongoid

class Person
  include Mongoid::Document
  store_in :citizens
  embeds_many :presonal_addresses
end

class PersonalAddress
  include Mongoid::Document
  embeded_in :person
  store_in :addresses # but it seems not to work
end

我希望将rails中的embeded doc类称为 PersonalAddress ,但将其存储在名为地址的属性中,而不是 personal_addresses

"citizens": {"_id": ..., "addresses": [{"_id":...},{..}]} but not:
citizens: {"_id": ..., "personal_addresses": [{"_id":...},{..}]}

有可能吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

class Person
  include Mongoid::Document
  store_in :citizens
  embeds_many :addresses, :class_name => "PersonalAddress"
end

class PersonalAddress
  include Mongoid::Document
  embeded_in :person, :inverse_of => :addresses
end