aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorwangjohn <wangjohn@mit.edu>2013-02-18 20:07:05 -0500
committerwangjohn <wangjohn@mit.edu>2013-02-25 00:29:28 -0500
commite52ff809606323f7370cfaf6e63b083f9b108d6c (patch)
tree21e150731afe39e38803ae2339febed32f4f1532 /activerecord/lib/active_record/persistence.rb
parent3762ee0baa2285bdc4a76d4d492fbe34a10cdc3a (diff)
downloadrails-e52ff809606323f7370cfaf6e63b083f9b108d6c.tar.gz
rails-e52ff809606323f7370cfaf6e63b083f9b108d6c.tar.bz2
rails-e52ff809606323f7370cfaf6e63b083f9b108d6c.zip
Raising an ActiveRecordError when one tries to use .touch(name) on a new
object that has not yet been persisted. This behavior follows the precedent set by update_columns.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 066f93635a..26c11b50a2 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -368,6 +368,8 @@ module ActiveRecord
# # triggers @brake.car.touch and @brake.car.corporation.touch
# @brake.touch
def touch(name = nil)
+ raise ActiveRecordError, "can not touch on a new record object" unless persisted?
+
attributes = timestamp_attributes_for_update_in_model
attributes << name if name