Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update a column without changing updated_at

This may sound like an odd request, however, I have am using impressionist, and using a cached hit column. I am also updating another column everytime it gets a hit, which is a separate calculation.

I don't want to update updated_at at this time, is there a way to skip that?

if impressionist(@topic, "message...", :unique => [:session_hash])
  @topic.increment(:exp, 1).save
end

Thanks

like image 332
Ricky Mason Avatar asked Dec 01 '22 17:12

Ricky Mason


2 Answers

The update_columns method from ActiveRecord::Persistence will do what you want.

like image 57
Jimmy Avatar answered Dec 25 '22 22:12

Jimmy


In addition to disabling timestamps for an entire class (which isn't thread safe), you can disable timestamps for an individual instance:

@topic.record_timestamps = false
@topic.increment(:exp, 1).save

This instance will not create or update timestamps until timestamps are re-enabled for it. This only affects this particular instance, other instances (even if they refer to the same row in the database) are not affected.

like image 27
Frederick Cheung Avatar answered Dec 25 '22 22:12

Frederick Cheung