Module: Mongoid::Touchable

Extended by:
Touchable
Included in:
Touchable
Defined in:
build/mongoid-7.0/lib/mongoid/touchable.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#define_touchable!(association) ⇒ Class

Add the association to the touchable relations if the touch option was provided.

Examples:

Add the touchable.

Model.define_touchable!(assoc)

Parameters:

  • association (Association)

    The association metadata.

Returns:

  • (Class)

    The model class.

Since:

  • 3.0.0



55
56
57
58
59
60
61
62
63
# File 'build/mongoid-7.0/lib/mongoid/touchable.rb', line 55

def define_touchable!(association)
  name = association.name
  method_name = define_relation_touch_method(name, association)
  association.inverse_class.tap do |klass|
    klass.after_save method_name
    klass.after_destroy method_name
    klass.after_touch method_name
  end
end