#615 ✓resolved
Lawrence Pit

Bug in many-to-many #replace method

Reported by Lawrence Pit | October 26th, 2008 @ 06:07 PM

Using the following model:

class Person
  include DataMapper::Resource
  property :id, Serial
  has n, :groups, :through => Resource
end

class Group
  include DataMapper::Resource
  property :id, Serial
  has n, :persons, :through => Resource
end

Then the following does not work:

p = Person.new
p.groups = [Group.new, Group.new]
p.save
p.reload
p.groups = [p.groups[0], Group.new]
p.save  # this fails

It will fail with the message "Duplicate entry '1-1' for key 1", because it tries to insert the first group again, while it still (or already) exists in the database.

I'd suggest it should either first remove the @orphaned resources before saving the new resources, or it should detect that a new resource equals an @orphaned resource and therefor should be ignored.

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

Attachments

Pages