-
-
Save slaskis/31594a7c27768a9dc879 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' | |
class Mother | |
include DataMapper::Resource | |
property :id, Serial | |
has 1, :baby | |
has 1, :child | |
end | |
class Baby | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
property :mother_id, Integer, :required => false # avoiding some IntegrityErrors | |
property :type, Discriminator | |
end | |
class Child < Baby | |
end | |
#DataMapper::Logger.new(STDOUT) | |
DataMapper.setup(:default, "sqlite3::memory:") | |
DataMapper.auto_migrate! | |
e = Mother.create | |
e.baby = Baby.create( :name => "One" ) | |
e.child = Child.create( :name => "Two" ) | |
e.save | |
puts "Works, the associations is two separate objects like expected." | |
p e | |
p e.baby | |
p e.child | |
e = Mother.create | |
#e.baby = Baby.create( :name => "One" ) | |
e.child = Child.create( :name => "Two" ) | |
e.save | |
puts "Fails, both associations is the same object even though only one is set." | |
p e | |
p e.baby | |
p e.child # i'd expect this to be nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment