ActiveRecord touch(:column) always also updates :updated_at?

You pretty much want to write custom SQL: def touch! Self.class. Update_all({:touched_at => Time.now.

Utc}, {:id => self. Id}) end This will generate this SQL: UPDATE posts SET touched_at = '2010-01-01 00:00:00.0000' WHERE id = 1 which is what you're after. If you call #save, this will end up calling create_with_timestamps or update_with_timestamps and these are what update the updated_on/updated_at/created_on/created_at columns By the way, the source for touch says it all.

You pretty much want to write custom SQL: def touch! Self.class. Update_all({:touched_at => Time.now.

Utc}, {:id => self. Id}) end This will generate this SQL: UPDATE posts SET touched_at = '2010-01-01 00:00:00.0000' WHERE id = 1 which is what you're after. If you call #save, this will end up calling #create_with_timestamps or #update_with_timestamps, and these are what update the updated_on/updated_at/created_on/created_at columns.By the way, the source for #touch says it all.

This seems to be the only way. Looks like the Rails 2.3.5 docs are just wrong. I'd add to you answer that I could put the touch!

Method in a callback on the model to finish replicating the functionality of ActiveRecord belongs_to's :touch => :column (which I think uses before_save and before_destroy, but I'd have to check the source). – tfe Sep 23 '10 at 18:50.

I'm trying to touch a column (:touched_at) without having it auto-update :updated_at, but watching the SQL queries, it always updates both to the current time. I thought it might be something to do with the particular model I was using it on, so I tried a couple different ones with the same result. Does anyone know what might be causing it to always set :updated_at when touching a different column?

Touch uses write_attribute internally, so it shouldn't be doing this. Some clarification... the Rails 2.3.5 docs for touch state that "If an attribute name is passed, that attribute is used for the touch instead of the updated_at/on attributes." But mine isn't acting that way.

Perhaps it's a case of the docs having drifted away from the actual state of the code?

Oops. Ignore that! By writing it down I figured out what I actually wanted to do Schedule.

Find(:all, :conditions => "schedule_id in ("1", "2", "3"), :order => "duration") where the 1, 2, 3 can be generated from the array prior to calling Blame it on Friday afternoon! :D.

Oops. Ignore that! By writing it down I figured out what I actually wanted to do.Schedule.

Find(:all, :conditions => "schedule_id in ("1", "2", "3"), :order => "duration") where the 1, 2, 3 can be generated from the array prior to calling. Blame it on Friday afternoon! :D.

I need to sort an array of ActiveRecord objects by the value in one of the columns but am unsure of how to do this. Example, I have an Schedule model that has a Duration column. I then have two arrays of Schedule objects OriginalList and NewList.

I want to sort each of those lists by Duration. However, this doesn't look right at all!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions