The active record documentation says the following:
Note that new records are different from any other record by definition, unless the other record is the receiver itself. Besides, if you fetch existing records with select and leave the ID out, you’re on your own, this predicate will return false.
But that’s really strange for me:
User.new == User.new
Since other data objects usually returns true if the containing data is equal:
String.new == String.new
OpenStruct.new == OpenStruct.new
Take a look on this code:
u1 = User.first
u1.name = ‘John Doe’
u2 = User.first
u2.name = ‘John Smith’
u1 == u2
The ActiveRecord::Base#== only compares the class and the id:
comparison_object.id == id
The method may be changed to compare the class and the attributes:
comparison_object.attributes == attributes
The latter will behave like other data objects on ruby.
I can overwrite this method only on my application or my model or even compare manually like this:
User.new.attributes == User.new.attributes
Regardless of that, the current behavior seems wrong.
There is a specific reason to the active record behavior be implemented in this way?