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":...},{..}]}
有可能吗?
谢谢!
答案 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