提交 701e48e4 编写于 作者: A Aaron Patterson

stop adding a new method for touch callbacks

上级 47617ecd
......@@ -91,15 +91,11 @@ def add_counter_cache_callbacks(reflection)
klass.attr_readonly cache_column if klass && klass.respond_to?(:attr_readonly)
end
def add_touch_methods(mixin)
return if mixin.method_defined? :belongs_to_touch_after_save_or_destroy
mixin.class_eval do
def belongs_to_touch_after_save_or_destroy(foreign_key, name, touch)
old_foreign_id = attribute_was(foreign_key)
def self.touch_record(o, foreign_key, name, touch) # :nodoc:
old_foreign_id = o.attribute_was(foreign_key)
if old_foreign_id
klass = association(name).klass
klass = o.association(name).klass
old_record = klass.find_by(klass.primary_key => old_foreign_id)
if old_record
......@@ -111,7 +107,7 @@ def belongs_to_touch_after_save_or_destroy(foreign_key, name, touch)
end
end
record = send name
record = o.send name
unless record.nil? || record.new_record?
if touch != true
record.touch touch
......@@ -120,18 +116,14 @@ def belongs_to_touch_after_save_or_destroy(foreign_key, name, touch)
end
end
end
end
end
def add_touch_callbacks(reflection)
add_touch_methods(mixin)
foreign_key = reflection.foreign_key
n = name
touch = options[:touch]
callback = lambda { |record|
record.belongs_to_touch_after_save_or_destroy foreign_key, n, touch
BelongsTo.touch_record(record, foreign_key, n, touch)
}
model.after_save callback
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册