Guest User

Untitled

a guest
Jan 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. require 'data_mapper'
  2.  
  3. DataMapper.setup(:default, "sqlite::memory:")
  4.  
  5. class Post
  6. include DataMapper::Resource
  7. property :id, Serial
  8. property :title, String
  9. after :create do
  10. self.title = "The id is #{id}"
  11. save
  12. end
  13. end
  14.  
  15. DataMapper.finalize
  16. DataMapper.auto_migrate!
  17.  
  18. post = Post.new
  19. if post.save
  20. puts 'Successfully saved.'
  21. else
  22. puts "Errors: #{post.errors.size}"
  23. end
  24. p DataMapper::VERSION, post, post.title
  25.  
  26. # called with 'ruby -rubygems saveaftercreate.rb' outputs:
  27. # Errors: 0
  28. # "1.1.0"
  29. # #<Post @id=1 @title="The id is 1">
  30. # "The id is 1"
Add Comment
Please, Sign In to add comment