method
add_touch_callbacks
rails latest stable - Class:
ActiveRecord::Associations::Builder::BelongsTo
add_touch_callbacks(reflection)public
No documentation available.
# 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