triAGENS/guacamole — pull request #15 by moonglum (2013-10-23 12:09:00+00:00)
Title: Are two model instances equal?

This is a spin-off from #3. Discussion:

@moonglum:
> With [the current] implementation, two models can only be equal if they have been saved. I think that's not a valid assumption :wink: I suggest using equalizer. It's a super thin gem. We can add all defined attributes to the equalizer, including key and rev. Then we get == for free (and also a nice .inspect)

@railsbros-dirk:
> I'm well aware of this issue :smile_cat: Let me explain the background: I spend some good amount of time struggling with strange errors in the [acceptance test][1]. The objects where just not equal. Guess what: They had different timestamps. In Ruby the timestamps had fractional seconds but when storing it to the database those were gone and after loading the object again the timestamps differed by some fractional seconds…
>
> I looked up how other frameworks are dealing with this issue and they just don't use the timestamps for equality checks. Furthermore they only use the `id` attribute to [determine the equality of objects][2]. As you said, an object which is not yet saved to the database will never be equal to itself. We could provide some mechanism to compare not yet persisted objects. But I think an persisted object and a non persisted should not be considered equal. Even if they have the same attributes.
>
> For now I would prefer it like this. The main reason is pragmatism and that ActiveRecord is doing it the same way. Changing this behavior should be discussed in a dedicated issue.
>
> [1]: https://github.com/triAGENS/guacamole/pull/3/files#diff-b16e13c501971d220ce3df6d5f418c0dR64
> [2]: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L286-L292

@moonglum:
> Ok, let's discuss this separately. Let's spin off a ticket for that tomorrow.
> (I'm also not sure if a dirty object and a clean object with the same ID should be considered equal :astonished:)