JoJoS
JoJoS

Reputation: 2041

How to update an attribute without touch

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') ?

Upvotes: 1

Views: 738

Answers (2)

Ronan Lopes
Ronan Lopes

Reputation: 3398

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.

Upvotes: -1

JoJoS
JoJoS

Reputation: 2041

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 !

Upvotes: 1

Related Questions