Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated readme about atomic updates.

  • Loading branch information...
commit 13c813fbe1c2dd213af1ecb293eb30961b244aa6 1 parent f70b91c
@jnunemaker authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 README.md
View
22 README.md
@@ -25,7 +25,27 @@ Including Toy::Mongo includes Toy::Store and then does a few things:
* Sets the key factory to object id
* Overrides get so that it also works with string representation of object id
* Overrides get_multi so that it performs one query instead of one query per id
-* Adds instance method atomic_update_attributes for persisting only the changes (see #persistable_changes)
+
+
+### Atomic Updates
+
+```ruby
+class User
+ include Toy::Mongo
+ include Toy::Mongo::AtomicUpdates
+
+ adapter :mongo_atomic, Mongo::Connection.new.db('adapter')['testing']
+
+ attribute :name, String
+ attribute :bio, String
+end
+
+user = User.create(:name => 'John', :bio => 'Awesome!')
+user.name = 'Nunes'
+user.save # Equivalent to update({:_id => user.id}, {'$set' => {'name' => 'Nunes'}})
+```
+
+Caveat: At this time it only works with simple data types. Complex types like Hash, Array, and Set are not supported. Oddness will ensue if you expect them to work as they can be manipuled through means other than assignment.
## Contributing
Please sign in to comment.
Something went wrong with that request. Please try again.