#119 ✓resolved
Sam Smoot

Kill MAGIC_PROPERTIES

Reported by Sam Smoot | January 1st, 2008 @ 11:14 PM

It was a quick and dirty hack to enable the usual timestamps (updated_at/created_at), but turns out it was a bad hack.

Now that :before_save callbacks are always called before the #dirty? check in #save, a model with an :updated_at property will always get updated, making the record dirty, meaning it always gets saved, even if no other attributes changed.

Which is bad.

I thought about modifying the lambda to something like:

lambda { |x| x.updated_at = Time::now if x.dirty? }

But not only would that be a double-hit calling #dirty? twice (once there, once in the body of #save), but if you had other before_save callbacks that did update the object's state, and make it dirty, you'd have unpredictable behaviour since there's no guarantee to the order callbacks are executed (they're stored in a Hash).

So...

Instead Adapter#create/#update should check for these special properties and do the updates there.

Comments and changes to this ticket

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Referenced by

Pages