Revert "`belongs_to :touch` behavior now touches old association when...

Revert "`belongs_to :touch` behavior now touches old association when transitioning to new association" until a proper fix is found for #10197
上级 5af29cbd
......@@ -110,26 +110,6 @@
*Neeraj Singh*
* `belongs_to :touch` behavior now touches old association when
transitioning to new association.
class Passenger < ActiveRecord::Base
belongs_to :car, touch: true
end
car_1 = Car.create
car_2 = Car.create
passenger = Passenger.create car: car_1
passenger.car = car_2
passenger.save
Previously only car_2 would be touched. Now both car_1 and car_2
will be touched.
*Adam Gamble*
* Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
These tasks should be supported by 3rd-party adapter.
......
......@@ -67,19 +67,8 @@ def belongs_to_counter_cache_after_update_for_#{name}
def add_touch_callbacks(reflection)
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
def belongs_to_touch_after_save_or_destroy_for_#{name}
foreign_key_field = #{reflection.foreign_key.inspect}
old_foreign_id = attribute_was(foreign_key_field)
if old_foreign_id
reflection_klass = #{reflection.klass}
old_record = reflection_klass.find_by(reflection_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
......
......@@ -176,32 +176,6 @@ def self.name; 'Toy'; end
assert_not_equal time, owner.updated_at
end
def test_changing_parent_of_a_record_touches_both_new_and_old_parent_record
klass = Class.new(ActiveRecord::Base) do
def self.name; 'Toy'; end
belongs_to :pet, touch: true
end
toy1 = klass.find(1)
old_pet = toy1.pet
toy2 = klass.find(2)
new_pet = toy2.pet
time = 3.days.ago.at_beginning_of_hour
old_pet.update_columns(updated_at: time)
new_pet.update_columns(updated_at: time)
toy1.pet = new_pet
toy1.save!
old_pet.reload
new_pet.reload
assert_not_equal time, new_pet.updated_at
assert_not_equal time, old_pet.updated_at
end
def test_clearing_association_touches_the_old_record
klass = Class.new(ActiveRecord::Base) do
def self.name; 'Toy'; end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册