Guest User

Untitled

a guest
Apr 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class Blogger < DataMapper::Base
  2. property :name, :string
  3. property :username, :string
  4. property :password, :string
  5. property :sig, :string
  6.  
  7. validates_uniqueness_of :name, :on => :create, :message => 'must be unique'
  8. validates_uniqueness_of :username, :on => :create, :message => 'must be unique'
  9.  
  10. has_many :posts
  11. end
  12.  
  13. class Post < DataMapper::Base
  14. property :title, :string
  15. property :body, :text, :lazy => true
  16. property :date, :string
  17. property :pic, :string
  18.  
  19. validates_uniqueness_of :title, :on => :create
  20. validates_uniqueness_of :pic, :on => :create
  21.  
  22. belongs_to :blogger
  23. end
  24.  
  25. database.save(Blogger)
  26. database.save(Post)
  27.  
  28. #Tests for now.
  29. blogger = Blogger.new
  30. blogger.name = 'ecin'
  31. blogger.username = 'ecin'
  32. blogger.password = '123'
  33. blogger.sig = 'ecin.png'
  34. blogger.save if blogger.valid?
  35.  
  36. post = Post.new
  37. post.blogger_id = blogger.id
  38. post.title = 'things are heating up!'
  39. post.body = 'they indeed are, aren\'t they? Amazing!'
  40. post.date = '2007-09-01'
  41. post.pic = '001.jpg'
  42. post.save if post.valid?
Add Comment
Please, Sign In to add comment