Guest User

Untitled

a guest
Oct 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. ## box.rb
  2. class Box
  3. include DataMapper::Resource
  4. property :id, Serial
  5. has n, :broken_toothpicks
  6. end
  7.  
  8. ## toothpick.rb
  9. class Toothpick
  10. include DataMapper::Resource
  11. property :id, Serial
  12. property :type, Discriminator
  13. belongs_to :box
  14. end
  15.  
  16. ## broken_toothpick.rb
  17. class BrokenToothpick < Toothpick
  18. property :pieces, Integer, :default => 2
  19. end
  20.  
  21. ## What happens?
  22.  
  23. ruby-1.8.7-p330 :001 > b = Box.create
  24. => #<Box @id=2>
  25. ruby-1.8.7-p330 :002 > b.broken_toothpicks
  26. => []
  27. ruby-1.8.7-p330 :003 > b.broken_toothpicks.create
  28. => #<BrokenToothpick @id=nil @type=BrokenToothpick @pieces=2 @box_id=nil>
  29. ruby-1.8.7-p330 :004 >
Add Comment
Please, Sign In to add comment