daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top