Identical objects are not ==
Reported by Paul Sadauskas (Rando) | November 21st, 2007 @ 12:11 AM | in 0.2.4 Release
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
- → State changed from new to resolved
- → Milestone changed from to 0.2.4 Release
- → Assigned user changed from to Nick Plante
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 Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
