-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
The callback update somehow gets blended into the push operator. Example:
class Person include Mongoid::Document has_and_belongs_to_many :awards, :inverse_of => nil embeds_many :somethings end class Award include Mongoid::Document has_many :persons, :inverse_of => :awards, :foreign_key => :award_ids end class Something include Mongoid::Document embedded_in :person field :name after_create :update_activity def update_activity person.awards.first.update_attributes(:updated_at => Time.now.utc) end end p = Person.create! a = Award.new p.awards << a s = Something.new :name => "first" p.somethings << s assert_equal 1, p.reload.somethings.count # this fails
the mongo push command looks like this:
MONGODB napa_test['people'].update(
, {"$pushAll"=>{"updated_at"=>[
{"name"=>"first", "_id"=>BSON::ObjectId('4e3733f2803544b95c000003')}]}}) #notice the incorrect updated_at
without the callback on Something, it looks like this, whish is obviously correct:
MONGODB napa_test['people'].update(
, {"$pushAll"=>{"somethings"=>[
{"name"=>"first", "_id"=>BSON::ObjectId('4e3734ef803544b970000003')}]}})