Created
May 21, 2009 21:59
-
-
Save gcampbell/115774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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