forked from cheald/mongomapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.rb
More file actions
40 lines (33 loc) · 1.01 KB
/
Copy pathkeys.rb
File metadata and controls
40 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$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'
key :links, Hash
timestamps!
end
User.collection.remove # empties collection
john = User.create({
:first_name => 'John',
:last_name => 'Nunemaker',
:age => 28,
:skills => ['ruby', 'mongo', 'javascript'],
:links => {"Google" => "http://www.google.com"}
})
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.links["Ruby on Rails"] = "http://www.rubyonrails.com"
john.save
pp john