Created
October 10, 2009 03:16
-
-
Save xxx/206559 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'dm-core' | |
class Foo | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :bars | |
end | |
class Bar | |
include DataMapper::Resource | |
property :id, Serial | |
# Does not belong to foo. | |
#belongs_to :foo, :nullable => true | |
def foo | |
puts 'I never get called.' | |
end | |
def foo=(other) | |
puts 'neither do i' | |
end | |
end | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
DataMapper.auto_migrate! | |
foo = Foo.create | |
foo.bars.create | |
bar = foo.bars.first | |
bar.foo = 'boom' | |
bar.foo # also boom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment