# Rails 2.3 Model.touch(:column) always also updates :updated\_at?

**URL:** <https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403>\
**Category:** Rails\
**Created:** [October 16, 2009, 1:59pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403 "2009-10-16T13:59:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 1:59pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/1 "2009-10-16T13:59:37Z")

</div>

Hi,

Am I the only one (i.e. something I do is wrong), or does the touch-  
method always update updated\_at, even though giving it a column to use  
INSTEAD is meant to update just that column???

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/2 "2009-10-16T15:19:13Z")

</div>

On Fri, Oct 16, 2009 at 4:57 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> 

Michael, is the attribute that you’re passing to the touch method a  
field of  
type datetime or date? If not, then it only makes  
sense that field that you’re passing to the touch method is one of  
those.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/3 "2009-10-16T15:19:13Z")

</div>

> Michael, is the attribute that you’re passing to the touch method a field of  
> type datetime or date? If not, then it only makes  
> sense that field that you’re passing to the touch method is one of those.

It is “datetime”.

But anyway, just looking at the code for “touch” I can’t see how it’s  
is supposed to NOT always write updated\_at - it uses write\_attribute  
which as far as I found out only changes the in-memory object, there  
must be a “save” somewhere else and that goe4s through the usual  
validations etc. There’s a lighthouse ticket for “touch” calling for  
it not to do validations ([Activity - rails](https://rails.lighthouseapp.com/projects/)  
8994-ruby-on-rails/tickets/2520-patch-activerecordtouch-without-  
validations).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/4 "2009-10-16T15:19:48Z")

</div>

In the mean time, can you work around this issue with something like:

Create a separate table with a 1:1 relationship to your current table  
Migrate the field you want to touch to the new table.  
Touch the field in that table, which will leave the updated\_at field  
in your original table alone.  
You could even make the new table without the timestamps fields, if you  
wanted.

–wpd

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/5 "2009-10-16T16:20:06Z")

</div>

So… I put it all into the mySQL triggers now. Saves a lot of  
ActiveRecord overhead anyway, and keeps this very low-level issue/  
optimization away from the “business logic” of the application.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/rails-2-3-model-touch-column-always-also-updates-updated-at/177403/6 "2009-10-16T15:23:19Z")

</div>

Well, I’m using separate timestamps for associated objects as an aid  
for cache-key generation, to avoid throwing out too many cache entries  
needlessly. I could look at the updated\_at of the associated items  
themselves - but guess what, I want to save database queries 🙂 So  
adding another table is not quite the way.  
I consider writing my own (SQL-based!) method, especially after  
finding out through the lighthouse ticket mentioned previously that  
all the validations are called. I have quite a few triggers and  
procedures in the database already anyway doing stuff behind rails’  
back, I would just like to limit those to certain critical areas, and  
a (non-frequent) timestamp update wasn’t on my list of things to do  
through trigger rather than through actvierecord.

Thanks,  
Michael

On Oct 16, 3:06 pm, Patrick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
…

> Create a separate table with a 1:1 relationship to your current table  
> …
