Sha256: 0fa4ca96881a6adeb9950fc78be79ef010a016aca241003f2cb1d3d672c4ca21

Contents?: true

Size: 899 Bytes

Versions: 11

Compression:

Stored size: 899 Bytes

Contents

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'

MongoMapper.database = 'testing'

class User
  include MongoMapper::Document

  key :first_name,  String, :required => true
  key :last_name,   String, :required => true
  key :token,       String, :default => lambda { 'some random string' }
  key :age,         Integer
  key :skills,      Array
  key :friend_ids,  Array, :typecast => 'ObjectId'
  timestamps!
end
User.collection.remove # empties collection

john = User.create({
  :first_name => 'John',
  :last_name  => 'Nunemaker',
  :age        => 28,
  :skills     => ['ruby', 'mongo', 'javascript'],
}) 

steve = User.create({
  :first_name => 'Steve',
  :last_name  => 'Smith',
  :age        => 29,
  :skills     => ['html', 'css', 'javascript', 'design'],
})

john.friend_ids << steve.id.to_s # will get typecast to ObjectId
john.save

pp john

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
mongo_mapper-unstable-2010.07.02 examples/keys.rb
mongo_mapper-unstable-2010.07.01 examples/keys.rb
mongo_mapper-unstable-2010.06.30 examples/keys.rb
mongo_mapper-unstable-2010.06.29 examples/keys.rb
mongo_mapper-unstable-2010.06.28 examples/keys.rb
mongo_mapper-unstable-2010.06.25 examples/keys.rb
mongo_mapper-unstable-2010.06.24 examples/keys.rb
mongo_mapper-unstable-2010.06.23 examples/keys.rb
mongo_mapper-0.8.2 examples/keys.rb
mongo_mapper-0.8.1 examples/keys.rb
mongo_mapper-0.8.0 examples/keys.rb