I have a situation where I need to use the updated_at
field of all the models to create a synchronize functionality. But In case of User model, the updated_at
field gets modified every time a user signs in. Even worse is the case, when a device signs in with a user's credentials to sync data updated_at
field just gets modified before sync has even started.
So, My question is, Is there a way we can stop devise to update the updated_at
field when a user signs in?
Here's what I did: override the should_record_timestamps? method on the devise model to not change the updated_at column when only the Devise fields are updated. Here's the code, it handles Devise::Trackable and Rememberable.
def should_record_timestamps?
(self.changes.keys.map(&:to_sym) - (Devise::Models::Trackable.required_fields(nil) + [:remember_token, :remember_created_at])).present? && super
end
This is a great way of not invalidating the caches when a user logs in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With