Guest User

Untitled

a guest
May 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. ## irb
  2. # DM adds f9311300-ea87-416f-8f4a-0cf62ed2059d to each record's id
  3. # User.first.id => f9311300-ea87-416f-8f4a-0cf62ed2059d (!)
  4. User.first.posts.create(:title => "Lorem ipsum")
  5.  
  6. ## couchdb log
  7. [info] [<0.319.0>] HTTP Error (code 404): {not_found,missing}
  8. [info] [<0.319.0>] 127.0.0.1 - - "GET /posts/f9311300-ea87-416f-8f4a-0cf62ed2059d" 404
  9. [info] [<0.321.0>] 127.0.0.1 - - "POST /posts/_temp_view" 200
  10. [info] [<0.322.0>] 127.0.0.1 - - "POST /posts/_temp_view" 200
  11. [info] [<0.325.0>] 127.0.0.1 - - "PUT /posts/4d68ecad-4a84-4f84-8dc1-cbd98dedad00f9311300-ea87-416f-8f4a-0cf62ed2059d" 201
  12.  
  13. ## Post Model
  14. class Post
  15. include DataMapper::Resource
  16.  
  17. property :id, String, :key => true, :field => :_id, :length => 36, :unique => true, :default => lambda { ::UUID.random_create.to_s }
  18. property :revision, String, :field => :_rev
  19. property :attachments, JsonObject, :field => :_attachments
  20. property :user_id, String, :key => true, :length => 36, :nullable => false
  21. property :title, String, :nullable => false, :length => (1..255)
  22.  
  23. repository(:default) do
  24. belongs_to :user
  25. end
  26. end
  27.  
  28. ## User Model
  29. class User
  30. include DataMapper::Resource
  31.  
  32. property :id, String, :key => true, :length => 36, :unique => true, :default => lambda { ::UUID.random_create.to_s }
  33. property :login, String, :nullable => false, :length => (3..50), :unique => true
  34. property :password, String, :nullable => false, :length => (6..50)
  35.  
  36. repository(:posts) do
  37. has n, :posts
  38. end
  39.  
  40. def self.default_repository_name; :default; end
  41. end
Add Comment
Please, Sign In to add comment