Module | Sequel::Plugins::Touch |
In: |
lib/sequel/plugins/touch.rb
|
The touch plugin adds a touch method to model instances, which saves the object with a modified timestamp. By default, it uses the :updated_at column, but you can set which column to use. It also supports touching of associations, so that when the current model object is updated or destroyed, the associated rows in the database can have their modified timestamp updated to the current timestamp.
Since the instance touch method works on model instances, it uses Time.now for the timestamp. The association touching works on datasets, so it updates all related rows in a single query, using the SQL standard CURRENT_TIMESTAMP. Both of these can be overridden easily if necessary.
TOUCH_COLUMN_DEFAULT | = | :updated_at | The default column to update when touching |
Set the touch_column and touched_associations variables for the model. Options:
# File lib/sequel/plugins/touch.rb, line 29 29: def self.configure(model, opts={}) 30: model.touch_column = opts[:column] || TOUCH_COLUMN_DEFAULT if opts[:column] || !model.touch_column 31: model.instance_variable_set(:@touched_associations, {}) 32: model.touch_associations(opts[:associations]) if opts[:associations] 33: end