Skip to content

Commit

Permalink
Revert "belongs_to :touch behavior now touches old association when…
Browse files Browse the repository at this point in the history
… transitioning to new association" until a proper fix is found for #10197
  • Loading branch information
dhh committed Apr 23, 2013
1 parent 5af29cb commit 7389df1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 58 deletions.
20 changes: 0 additions & 20 deletions activerecord/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -110,26 +110,6 @@


*Neeraj Singh* *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 * Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
These tasks should be supported by 3rd-party adapter. These tasks should be supported by 3rd-party adapter.


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,19 +67,8 @@ def belongs_to_counter_cache_after_update_for_#{name}
def add_touch_callbacks(reflection) def add_touch_callbacks(reflection)
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
def belongs_to_touch_after_save_or_destroy_for_#{name} 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} record = #{name}
unless record.nil? || record.new_record? unless record.nil? || record.new_record?
record.touch #{options[:touch].inspect if options[:touch] != true} record.touch #{options[:touch].inspect if options[:touch] != true}
end end
Expand Down
26 changes: 0 additions & 26 deletions activerecord/test/cases/timestamp_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -176,32 +176,6 @@ def self.name; 'Toy'; end
assert_not_equal time, owner.updated_at assert_not_equal time, owner.updated_at
end 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 def test_clearing_association_touches_the_old_record
klass = Class.new(ActiveRecord::Base) do klass = Class.new(ActiveRecord::Base) do
def self.name; 'Toy'; end def self.name; 'Toy'; end
Expand Down

0 comments on commit 7389df1

Please sign in to comment.