Skip to content

Instantly share code, notes, and snippets.

@martinemde
Created December 28, 2009 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinemde/264903 to your computer and use it in GitHub Desktop.
Save martinemde/264903 to your computer and use it in GitHub Desktop.
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