Class: ActiveRecord::Associations::Builder::SingularAssociation

Inherits:
Association show all
Defined in:
activerecord/lib/active_record/associations/builder/singular_association.rb

Overview

:nodoc:

Direct Known Subclasses

BelongsTo, HasOne

Constant Summary

Constants inherited from Association

Association::VALID_OPTIONS

Class Method Summary collapse

Methods inherited from Association

build, create_reflection

Class Method Details

.define_callbacks(model, reflection) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 56

def self.define_callbacks(model, reflection)
  super

  # If the record is saved or destroyed and `:touch` is set, the parent
  # record gets a timestamp updated. We want to know about it, because
  # deleting the association would change that side-effect and perhaps there
  # is code relying on it.
  if reflection.deprecated? && reflection.options[:touch]
    model.before_save do
      report_deprecated_association(reflection, context: ":touch has a side effect here")
    end

    model.before_destroy do
      report_deprecated_association(reflection, context: ":touch has a side effect here")
    end
  end
end