-
-
Save jm81/245058 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
#!/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 | |
end | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
DataMapper.auto_migrate! | |
# Bar#foo and Bar#foo= will get called if they're added after DataMapper.setup | |
class Bar | |
def foo | |
puts 'I never get called.' | |
end | |
def foo=(other) | |
puts 'neither do i' | |
end | |
end | |
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