Skip to content

Instantly share code, notes, and snippets.

@iamjwc
Created April 12, 2011 15:32
Show Gist options
  • Save iamjwc/915724 to your computer and use it in GitHub Desktop.
Save iamjwc/915724 to your computer and use it in GitHub Desktop.
# This script demonstrates an issue with MongoMapper's #update_attributes!.
# Should call $set, but instead, just overwrites the entire doc.
#
# Script outputs:
#
# doc[:one] # => "uno"
# doc[:two] # => nil
class Doc
include MongoMapper::Document
key :one, String
key :two, String
end
doc = Doc.create!
Doc.collection.update({
:_id => doc.id
}, {
:$set => {
:two => "dos"
}
})
doc.update_attributes!(:one => "uno")
doc.reload
puts "doc[:one] # => #{doc.one.inspect}"
puts "doc[:two] # => #{doc.two.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment