Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3:///tmp/bug.db')
class Sheep
include DataMapper::Resource
property :id, Serial
property :name, String, :unique_index => true
has n, :fleas
before :save do
puts "sheep before save..."
end
end
class Flea
include DataMapper::Resource
property :id, Serial
property :position, String
belongs_to :sheep, :required => false
before :save do
puts "flea before save..."
end
end
DataMapper.auto_migrate!
@sheep = Sheep.new(:name => 'Shaun')
50.times { |i| @sheep.fleas.build(:position => i.to_s) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment