
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
-
Sam Smoot January 2nd, 2008 @ 03:43 PM
- Assigned user set to Bernerd Schaefer
- State changed from new to open
I think Bernerd resolved this?
-
Sam Smoot January 2nd, 2008 @ 04:00 PM
- Milestone cleared.
-
Bernerd Schaefer January 3rd, 2008 @ 05:23 PM
Yeah. I added #update_magic_properties to DataObjectAdapter.
-
Sam Smoot January 4th, 2008 @ 05:56 PM
- State changed from open to resolved
So I think this is fine for now. Closing this out.
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.
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
- Nobody is watching this ticket.
Tags
Referenced by
-
133 "created_at" updated to new time when update_attributes is called I believe this may be linked to this ticket
-
133 "created_at" updated to new time when update_attributes is called Problem lies in DataObjectAdapter#update_magic_propertie...