#622 ✓resolved
Lawrence Pit

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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages