Permalink
Browse files

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

… transitioning to new association" until a proper fix is found for #10197
  • Loading branch information...
1 parent 5af29cb commit 7389df139a35436f00876c96d20e81ba23c93f0a @dhh dhh committed Apr 23, 2013
View
20 activerecord/CHANGELOG.md
@@ -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.
View
13 activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -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
View
26 activerecord/test/cases/timestamp_test.rb
@@ -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

0 comments on commit 7389df1

Please sign in to comment.