diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-04-23 09:23:57 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-04-23 09:23:57 -0700 |
commit | 7389df139a35436f00876c96d20e81ba23c93f0a (patch) | |
tree | 9ce85c2ec6057aec81acbf330682059d57d50471 | |
parent | 5af29cbde8c10f081bd8216338d0cdb661e23fb3 (diff) | |
download | rails-7389df139a35436f00876c96d20e81ba23c93f0a.tar.gz rails-7389df139a35436f00876c96d20e81ba23c93f0a.tar.bz2 rails-7389df139a35436f00876c96d20e81ba23c93f0a.zip |
Revert "`belongs_to :touch` behavior now touches old association when transitioning to new association" until a proper fix is found for #10197
-rw-r--r-- | activerecord/CHANGELOG.md | 20 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 26 |
3 files changed, 1 insertions, 58 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index d47a23b8f5..66c73bfe0f 100644 --- a/activerecord/CHANGELOG.md +++ b/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. diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 092230b2f7..c3026dc23c 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -67,19 +67,8 @@ module ActiveRecord::Associations::Builder 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 diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 9d84f64c96..22c5da3faa 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -176,32 +176,6 @@ class TimestampTest < ActiveRecord::TestCase 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 |