Flowdock
method

add_touch_callbacks

Importance_0
v4.0.2 - Show latest stable - 0 notes - Class: BelongsTo
add_touch_callbacks(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/belongs_to.rb, line 69
    def add_touch_callbacks(reflection)
      mixin.class_eval         def belongs_to_touch_after_save_or_destroy_for_#{name}          foreign_key_field = #{reflection.foreign_key.inspect}          old_foreign_id    = changed_attributes[foreign_key_field]          if old_foreign_id            klass      = association(#{name.inspect}).klass            old_record = klass.find_by(klass.primary_key => old_foreign_id)            if old_record              old_record.touch #{options[:touch].inspect if options[:touch] != true}            end          end          record = #{name}          unless record.nil? || record.new_record?            record.touch #{options[:touch].inspect if options[:touch] != true}          end        end, __FILE__, __LINE__ + 1

      model.after_save    "belongs_to_touch_after_save_or_destroy_for_#{name}"
      model.after_touch   "belongs_to_touch_after_save_or_destroy_for_#{name}"
      model.after_destroy "belongs_to_touch_after_save_or_destroy_for_#{name}"
    end
Register or log in to add new notes.