| Module | Sequel::Plugins::Touch::ClassMethods |
| In: |
lib/sequel/plugins/touch.rb
|
| touch_column | [RW] | The column to modify when touching a model instance, as a symbol. Also used as the default column when touching associations, if the associations don‘t specify a column. |
| touched_associations | [R] | A hash specifying the associations to touch when instances are updated or destroyed. Keys are association dataset method name symbols and values are column name symbols. |
Set the touch_column for the subclass to be the same as the current class. Also, create a copy of the touched_associations in the subclass.
# File lib/sequel/plugins/touch.rb, line 48
48: def inherited(subclass)
49: super
50: subclass.touch_column = touch_column
51: subclass.instance_variable_set(:@touched_associations, touched_associations.dup)
52: end
Add additional associations to be touched. See the :association option of the Sequel::Plugin::Touch.configure method for the format of the associations arguments.
# File lib/sequel/plugins/touch.rb, line 57
57: def touch_associations(*associations)
58: associations.flatten.each do |a|
59: a = {a=>touch_column} if a.is_a?(Symbol)
60: a.each do |k,v|
61: raise(Error, "invalid association: #{k}") unless r = association_reflection(k)
62: touched_associations[r.dataset_method] = v
63: end
64: end
65: end