Skip to content

Commit

Permalink
Added set modifier example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jul 9, 2010
1 parent 8cd51bc commit f1e52bc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/modifiers/set.rb
@@ -0,0 +1,25 @@
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'

MongoMapper.database = 'testing'

class User
include MongoMapper::Document

key :name, String
key :tags, Array
end
User.collection.remove # empties collection

john = User.create(:name => 'John', :tags => %w[ruby mongo], :age => 28)
bill = User.create(:name => 'Bill', :tags => %w[ruby mongo], :age => 30)

User.set({:name => 'John'}, :tags => %[ruby])
pp john.reload

User.set(john.id, :tags => %w[ruby mongo])
pp john.reload

john.set(:tags => %w[something different])
pp john.reload

0 comments on commit f1e52bc

Please sign in to comment.