From a215ca63355d7c404db6d2daae868a80c0aa23b6 Mon Sep 17 00:00:00 2001 From: Washington Luiz Date: Fri, 14 Mar 2014 19:44:07 -0300 Subject: Update callbacks executed on AR::Base#touch [skip ci] As of https://github.com/rails/rails/pull/12031 after_commit and after_rollback are also executed --- activerecord/lib/active_record/persistence.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 4e63206cf4..d85fad1e13 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -405,8 +405,8 @@ module ActiveRecord end # Saves the record with the updated_at/on attributes set to the current time. - # Please note that no validation is performed and only the +after_touch+ - # callback is executed. + # Please note that no validation is performed and only the +after_touch+, + # +after_commit+ and +after_rollback+ callbacks are executed. # If an attribute name is passed, that attribute is updated along with # updated_at/on attributes. # -- cgit v1.2.3 From c80ca4c7803b4e8ed7f125ada9acc6b7c499af5f Mon Sep 17 00:00:00 2001 From: Thiago Pinto Date: Wed, 19 Mar 2014 21:13:03 -0400 Subject: ActiveRecord#touch should accept multiple attributes #14423 --- activerecord/lib/active_record/persistence.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index d85fad1e13..eb45289b2e 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -412,6 +412,7 @@ module ActiveRecord # # product.touch # updates updated_at/on # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on + # product.touch(:started_at, :ended_at) # updates started_at, ended_at and updated_at/on attributes # # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object. # @@ -432,11 +433,11 @@ module ActiveRecord # ball = Ball.new # ball.touch(:updated_at) # => raises ActiveRecordError # - def touch(name = nil) + def touch(*names) raise ActiveRecordError, "cannot touch on a new record object" unless persisted? attributes = timestamp_attributes_for_update_in_model - attributes << name if name + attributes.concat(names) unless attributes.empty? current_time = current_time_from_proper_timezone -- cgit v1.2.3 From bebe4a9ddde078c091e48ab06c4ca4c8da37203f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 20 Mar 2014 08:08:22 -0300 Subject: Improve touch docs with extra attributes passed in [ci skip] --- activerecord/lib/active_record/persistence.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index eb45289b2e..c20499d081 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -407,14 +407,16 @@ module ActiveRecord # Saves the record with the updated_at/on attributes set to the current time. # Please note that no validation is performed and only the +after_touch+, # +after_commit+ and +after_rollback+ callbacks are executed. - # If an attribute name is passed, that attribute is updated along with - # updated_at/on attributes. # - # product.touch # updates updated_at/on - # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on + # If attribute names are passed, they are updated along with updated_at/on + # attributes. + # + # product.touch # updates updated_at/on + # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on # product.touch(:started_at, :ended_at) # updates started_at, ended_at and updated_at/on attributes # - # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object. + # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on + # associated object. # # class Brake < ActiveRecord::Base # belongs_to :car, touch: true -- cgit v1.2.3