-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Consider the following:
Mongoid::Config.settings = { "host" => "127.0.0.1", "database" => "testing" } class Item include Mongoid::Document embedded_in :list field :name def who_am_i puts metadata.name end end class List include Mongoid::Document embeds_many :cool_items, :class_name => 'Item' embeds_many :simple_items, :class_name => 'Item' field :name end List.delete_all list = List.create! list.cool_items.create!(:name => 'cool') list.simple_items.create!(:name => 'uncool') cool_item = list.cool_items.first cool_item.who_am_i simple_item = list.simple_items.first simple_item.who_am_i
Gives:
<pre>
MONGODB testing['lists'].update(
, {"$push"=>{"cool_items"=>
{"_id"=>BSON::ObjectId('4df7f346b4e4cf3b41000002'), "name"=>"cool"}}})
MONGODB testing['lists'].update(
, {"$push"=>{"cool_items"=>
{"_id"=>BSON::ObjectId('4df7f346b4e4cf3b41000003'), "name"=>"uncool"}}})
cool_items
cool_items
</pre>
It can be partially worked-around if :inverse_of is added, but then it's impossible to use "CoolItem#list" method.