
Identical objects are not ==
Reported by Paul Sadauskas (Rando) | November 21st, 2007 @ 12:12 AM
When trying to compare two objects that are the same, Datamapper does not override ==. This is particularly annoying when trying to see if one object is included in a set of objects. Eg:
irb(main):001:0> p = Person[1]
=> #<Person:0x..fb66384c0 @new_record=false, @created_at=#<DateTime: 4908845/2,0,2299161>, @name="Paul Sadauskas", @updated_at=#<DateTime: 4908845/2,0,2299161>, @id=1>
irb(main):002:0> p == Person[1]
=> false
irb(main):003:0> Person.all.include? p
=> false
Attached is a patch the implements DataMapper::Base#== by comparing attributes, as well as a couple specs. I believe it to work, but can't run the specs myself because of some issues with installing the dm::sqlite3 driver.
Comments and changes to this ticket
-
Paul Sadauskas (Rando) November 21st, 2007 @ 12:02 PM
I got the do_sqlite gem installed, and was able to run my updated specs. I managed to break an unrelated one in acts_as_tree. Attached is an updated patch that fixes it.
-
Nick Plante November 21st, 2007 @ 04:56 PM
- Assigned user set to Nick Plante
- State changed from new to resolved
- Milestone cleared.
This patch only tests publicly visible attributes. I modified it to test all attributes (this involves a new private method on DM::Base called #private_attributes) and committed. Should be fixed in r512.
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 »