Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## irb
- # DM adds f9311300-ea87-416f-8f4a-0cf62ed2059d to each record's id
- # User.first.id => f9311300-ea87-416f-8f4a-0cf62ed2059d (!)
- User.first.posts.create(:title => "Lorem ipsum")
- ## couchdb log
- [info] [<0.319.0>] HTTP Error (code 404): {not_found,missing}
- [info] [<0.319.0>] 127.0.0.1 - - "GET /posts/f9311300-ea87-416f-8f4a-0cf62ed2059d" 404
- [info] [<0.321.0>] 127.0.0.1 - - "POST /posts/_temp_view" 200
- [info] [<0.322.0>] 127.0.0.1 - - "POST /posts/_temp_view" 200
- [info] [<0.325.0>] 127.0.0.1 - - "PUT /posts/4d68ecad-4a84-4f84-8dc1-cbd98dedad00f9311300-ea87-416f-8f4a-0cf62ed2059d" 201
- ## Post Model
- class Post
- include DataMapper::Resource
- property :id, String, :key => true, :field => :_id, :length => 36, :unique => true, :default => lambda { ::UUID.random_create.to_s }
- property :revision, String, :field => :_rev
- property :attachments, JsonObject, :field => :_attachments
- property :user_id, String, :key => true, :length => 36, :nullable => false
- property :title, String, :nullable => false, :length => (1..255)
- repository(:default) do
- belongs_to :user
- end
- end
- ## User Model
- class User
- include DataMapper::Resource
- property :id, String, :key => true, :length => 36, :unique => true, :default => lambda { ::UUID.random_create.to_s }
- property :login, String, :nullable => false, :length => (3..50), :unique => true
- property :password, String, :nullable => false, :length => (6..50)
- repository(:posts) do
- has n, :posts
- end
- def self.default_repository_name; :default; end
- end
Add Comment
Please, Sign In to add comment