I need to override the rails update_all method so that it will update updated_at field for specific models.
I have added following module in app/config/intializer/xyzfile.rb :
module ActiveRecord
class Relation
def update_all_with_updated_at(updates)
case updates
when Hash
updates.reverse_merge!(updated_at: Time.now)
when String
updates += ", updated_at = '#{Time.now.to_s(:db)}'"
when Array
updates[0] += ', updated_at = ?'
updates << Time.now
end
update_all_without_updated_at(updates)
end
alias_method_chain :update_all, :updated_at
end
end
I want to use this for specific models, How can I do this?
- Adding updated_at in each update_all is one of the solutions but I am looking for a solution with which I can override update_all method.