Skip to content

Instantly share code, notes, and snippets.

@gcampbell
Created May 21, 2009 21:59
Show Gist options
  • Save gcampbell/115774 to your computer and use it in GitHub Desktop.
Save gcampbell/115774 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, 'sqlite3::memory:')
class Zoo
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :animals
end
class Animal
include DataMapper::Resource
property :id, Serial
property :species, String
belongs_to :zoo
end
DataMapper.auto_migrate!
Zoo.create(:name => "old").animals.create(:species => "tiger")
animal = Zoo.first.animals.first
animal.zoo.name = "new!"
puts animal.zoo.save # "true"
puts animal.zoo.name # "new!"
puts animal.zoo.dirty? # "true"
puts animal.zoo.reload.name # "old"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment