Forum: Rails-core (closed, excessive spam) Is it legal to override AR:Base#== and #eql?

Bce1d1b7c3ec7b577dcb42e254899e6b?d=identicon&s=25 Michael Schuerig (Guest)
on 2008-05-06 22:05
(Received via mailing list)
I have several cases of models where object identity is not important,
but only the (guaranteed) unique combination of attribute values. In
these cases it is convenient to override #== in a way that two objects
with the same attribute values but different IDs are still considered
equal. This is very handy when assigning to has_many associations
because then existing associated objects are not touched (deleted in
particular) and foreign key constraints of other references to these
objects are not violated.

My only concern is that something inside AR might depend on #== being
tied to database object identity.

Michael

--
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/
Efa76b164a7de4a5730e4fa397cc4425?d=identicon&s=25 Michael Koziarski (Guest)
on 2008-05-07 03:27
(Received via mailing list)
>  My only concern is that something inside AR might depend on #== being
>  tied to database object identity.

There's nothing that I'm aware of.  However I'd definitely say this is
'unsupported hackery', so if something does break you'll kinda be on
your own.   Do let us know though ;)


--
Cheers

Koz
Bce1d1b7c3ec7b577dcb42e254899e6b?d=identicon&s=25 Michael Schuerig (Guest)
on 2008-05-07 09:20
(Received via mailing list)
On Wednesday 07 May 2008, Michael Koziarski wrote:
> >  My only concern is that something inside AR might depend on #==
> > being tied to database object identity.
>
> There's nothing that I'm aware of.  However I'd definitely say this
> is 'unsupported hackery', so if something does break you'll kinda be
> on your own.   Do let us know though ;)

That's about what I thought :-| I think it should be stated in the docs
one way or another, however, I don't yet know which way it is.

Michael

--
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/
This topic is locked and can not be replied to.