-
-
Save markiz/1442832 to your computer and use it in GitHub Desktop.
test case for apparent DataMapper bug when recursively saving associations
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
Gemfile.lock |
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
source :rubygems | |
DM_VERSION = "1.2.0" | |
gem "dm-core", DM_VERSION | |
gem "dm-constraints", DM_VERSION | |
gem "dm-migrations", DM_VERSION | |
gem "dm-sqlite-adapter", DM_VERSION |
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 | |
# encoding: UTF-8 | |
# test case for apparent DataMapper bug when recursively saving associations | |
require "rubygems" | |
require "dm-core" | |
#require "dm-constraints" | |
require "dm-migrations" | |
#DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, "sqlite::memory:") | |
DataMapper::Model.raise_on_save_failure = true | |
# models | |
class Person | |
include DataMapper::Resource | |
property :id, Serial | |
has 1, :pet, "Dog", :child_key => :owner_id | |
end | |
class Dog | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :owner, "Person" | |
has n, :parasites, :child_key => :host_id | |
end | |
class Parasite | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :host, "Dog" | |
end | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
# generate data | |
bug = Parasite.new | |
pet = Dog.new :parasites => [bug] | |
guy = Person.new :pet => pet | |
puts "[INFO] SAVING" | |
guy.save | |
puts [guy, pet, bug].map(&:saved?).join(" / ") | |
puts [guy, pet, bug].map(&:inspect) | |
puts bug.host_id # nil! | |
puts bug.dirty? # true => unsaved! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment