
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
-
Dan Kubb (dkubb) December 1st, 2008 @ 02:28 AM
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
- State changed from new to open
-
Dan Kubb (dkubb) December 4th, 2008 @ 03:54 AM
- State changed from open to accepted
-
Jonathan Stott (namelessjon) February 22nd, 2009 @ 01:34 PM
- Tag set to many-to-many, one_file_test
This fails as of 02a93b11ce576361789340f78babf7bd4f796161 due to replace not being implemented, however the attached test should verify the problem, or lack thereof, when it is.
-
Dan Kubb (dkubb) May 28th, 2009 @ 03:34 AM
- State changed from accepted to resolved
I can confirm this is resolved in dm-core/next. Jonathan's script passes perfectly.
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 »