Reputation: 2130
I have a process which iterates through a bunch of ActiveRecord models, does some processing, and saves the models again. Often though, the processing doesn't result in an changes to the attributes and so the updated_at
column never changes (even though save is called).
I'd prefer not to disable partial updates (in general, they're useful). I'm guessing that my two options are to:
processed_at
') and manage this myself, although this seems a bit wasteful/redundant.updated_at
attribute?I've heard that Rails 3 will have a 'touch' method which would be exactly what I'm looking for.
Any ideas/options/opinions?
Upvotes: 30
Views: 15085
Reputation: 417
Now that the 2.3.x line has come and gone, a more definitive answer is that touch didn't make it into ActiveRecord until 2.3.8. So, anyone using still using Rails 2.3.2 (as the OP was -- and as I currently am) will need to find another way to "touch" their records.
Upvotes: 1
Reputation: 115362
Actually the touch
method is already in Rails 2.3.x, so you can simply do:
model.touch
To update the updated_at
column. Alternatively, to update some other column with the current date and time use:
model.touch(:column_name)
Upvotes: 52