Skip to content

Instantly share code, notes, and snippets.

@jm81
Forked from xxx/gist:206559
Created November 29, 2009 20:39
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 jm81/245058 to your computer and use it in GitHub Desktop.
Save jm81/245058 to your computer and use it in GitHub Desktop.
#!/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