How to update an attribute without touch

707 Views Asked by At

Is there an option to not touch the updated_at attribute when i update an attribute in mongoid ?

Something similar to model.save(validate: false) or, better, model.update_attribute(:attribute, 'value') ?

2

There are 2 best solutions below

0
JoJoS On BEST ANSWER

I just found my answer here : https://github.com/mongoid/mongoid/blob/v3.1.7/lib/mongoid/timestamps/timeless.rb

If anyone is interested, you can use model.timeless to skip updating created or update date, and model.clear_timeless_option to reactivate it !

1
Ronan Lopes On

You can use the update_column method:

https://apidock.com/rails/v3.1.0/ActiveRecord/Persistence/update_column

Validations are skipped.

Callbacks are skipped.

updated_at/updated_on are not updated.