method
add_touch_callbacks
v4.0.2 -
Show latest stable
-
0 notes -
Class: BelongsTo
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
add_touch_callbacks(reflection)
public
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