Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## box.rb
- class Box
- include DataMapper::Resource
- property :id, Serial
- has n, :broken_toothpicks
- end
- ## toothpick.rb
- class Toothpick
- include DataMapper::Resource
- property :id, Serial
- property :type, Discriminator
- belongs_to :box
- end
- ## broken_toothpick.rb
- class BrokenToothpick < Toothpick
- property :pieces, Integer, :default => 2
- end
- ## What happens?
- ruby-1.8.7-p330 :001 > b = Box.create
- => #<Box @id=2>
- ruby-1.8.7-p330 :002 > b.broken_toothpicks
- => []
- ruby-1.8.7-p330 :003 > b.broken_toothpicks.create
- => #<BrokenToothpick @id=nil @type=BrokenToothpick @pieces=2 @box_id=nil>
- ruby-1.8.7-p330 :004 >
Add Comment
Please, Sign In to add comment