diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-07-09 14:11:51 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-13 07:03:42 +0200 |
commit | 1d45ea081493cd4eca95cd75cce7be7b8d9cb07c (patch) | |
tree | ebf901a60827701e5e09c45d8d0cd24a4f69967d /activerecord/lib/active_record | |
parent | 2aed63eb526b5493df63151e2bf451d55114c49a (diff) | |
download | rails-1d45ea081493cd4eca95cd75cce7be7b8d9cb07c.tar.gz rails-1d45ea081493cd4eca95cd75cce7be7b8d9cb07c.tar.bz2 rails-1d45ea081493cd4eca95cd75cce7be7b8d9cb07c.zip |
with this fix touch method - does not call validations - doest not call callbacks - updates updated_at/on along with attribute if attribute is provided - marks udpated_at/on and attribute as NOT changed
[#2520 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/timestamp.rb | 16 |
2 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 828a8b41b6..44264bec7f 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -111,6 +111,7 @@ module ActiveRecord if record_update_timestamps timestamp_attributes_for_update_in_model.each do |column| hash[column] = read_attribute(column) + @changed_attributes.delete(column.to_s) end end diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 1075a60f07..5cddd07e82 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -21,24 +21,22 @@ module ActiveRecord end # Saves the record with the updated_at/on attributes set to the current time. - # If the save fails because of validation errors, an - # ActiveRecord::RecordInvalid exception is raised. If an attribute name is passed, - # that attribute is used for the touch instead of the updated_at/on attributes. + # Please note that no validation is performed and no callbacks are executed. + # If an attribute name is passed, that attribute is updated along with + # updated_at/on attributes. # # Examples: # - # product.touch # updates updated_at - # product.touch(:designed_at) # updates the designed_at attribute + # product.touch # updates updated_at/on + # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on def touch(attribute = nil) current_time = current_time_from_proper_timezone if attribute - write_attribute(attribute, current_time) + self.update_attribute(attribute, current_time) else - timestamp_attributes_for_update_in_model.each { |column| write_attribute(column.to_s, current_time) } + timestamp_attributes_for_update_in_model.each { |column| self.update_attribute(column, current_time) } end - - save! end private |