method

add_touch_callbacks

Importance_0
v7.0.0 - Show latest stable - 0 notes - Class: HasOne
add_touch_callbacks(model, reflection) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations/builder/has_one.rb, line 47
    def self.add_touch_callbacks(model, reflection)
      name  = reflection.name
      touch = reflection.options[:touch]

      callback = -> (record) { HasOne.touch_record(record, name, touch) }
      model.after_create callback, if: :saved_changes?
      model.after_create_commit { association(name).reset_negative_cache }
      model.after_update callback, if: :saved_changes?
      model.after_destroy callback
      model.after_touch callback
    end

    private_class_method :macro, :valid_options, :valid_dependent_options, :add_destroy_callbacks,
      :define_callbacks, :define_validations, :add_touch_callbacks
  end
end
Register or log in to add new notes.