
one-to-many association replace method bug
Reported by Lawrence Pit | October 30th, 2008 @ 07:34 AM
#!/usr/bin/env ruby
require 'rubygems'
gem 'dm-core', '>=0.9.6'
require 'dm-core'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
# Setup
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :nullable => false
has n, :tags
end
class Tag
include DataMapper::Resource
property :id, Serial
property :name, String, :nullable => false
belongs_to :post
end
DataMapper.auto_migrate!
post = Post.new(:title => "foo")
post.tags.build(:name => "tag1")
post.tags.build(:name => "tag2")
post.save
post2 = Post.create(:title => "bar")
Tag.create(:name => "tag3", :post => post2)
Tag.create(:name => "tag4", :post => post2)
post.reload
post.tags = [Tag.get(2), Tag.get(3)]
post.save
p Tag.get(1)
With gem v0.9.7 this results in output:
UPDATE "tags" SET "post_id" = NULL WHERE ("id" = 1)
UPDATE "tags" SET "post_id" = 1 WHERE ("id" = 3)
#<Tag id=1 name="tag1" post_id=nil>
With edge (Oct 30, 2008) this results in output:
UPDATE "tags" SET "post_id" = 1 WHERE ("id" = 3)
#<Tag id=1 name="tag1" post_id=1>
In both cases wrong behaviour.
Expected behaviour: it should DELETE tag with id=1, not update it, nor ignore it.
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 8th, 2009 @ 05:05 AM
- State changed from new to accepted
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
-
Dan Kubb (dkubb) May 16th, 2009 @ 02:01 AM
- State changed from accepted to resolved
I can confirm this is fixed in dm-core/next
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »