diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 21:44:30 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-27 21:44:30 -0700 |
commit | 3ba552fb2900ce67409af57f3c7a1f9fda4c10d3 (patch) | |
tree | fa3db96769d699bc7bdb4623d727c7302b0d6159 /activerecord/lib/active_record | |
parent | 307ec3db0fe26cbd1811d34a27e6637726ce23ce (diff) | |
parent | e780e2fda326fa5ea616e1441a6ed81b2890085c (diff) | |
download | rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.tar.gz rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.tar.bz2 rails-3ba552fb2900ce67409af57f3c7a1f9fda4c10d3.zip |
Merge pull request #18225 from DanOlson/update-without-changing-timestamps
Provide :touch option to save() to accommodate saving without updating t...
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/timestamp.rb | 6 |
3 files changed, 10 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 523d492a48..497ce8c15c 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -298,7 +298,7 @@ module ActiveRecord private - def create_or_update #:nodoc: + def create_or_update(*) #:nodoc: _run_save_callbacks { super } end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index bb1d01d089..ded190c111 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -116,8 +116,8 @@ module ActiveRecord # # Attributes marked as readonly are silently ignored if the record is # being updated. - def save(*) - create_or_update + def save(*args) + create_or_update(*args) rescue ActiveRecord::RecordInvalid false end @@ -138,8 +138,8 @@ module ActiveRecord # # Attributes marked as readonly are silently ignored if the record is # being updated. - def save!(*) - create_or_update || raise(RecordNotSaved.new(nil, self)) + def save!(*args) + create_or_update(*args) || raise(RecordNotSaved.new(nil, self)) end # Deletes the record in the database and freezes this instance to @@ -498,9 +498,9 @@ module ActiveRecord relation end - def create_or_update + def create_or_update(*args) raise ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? - result = new_record? ? _create_record : _update_record + result = new_record? ? _create_record : _update_record(*args) result != false end diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 936a18d99a..4d1d7310af 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -57,8 +57,8 @@ module ActiveRecord super end - def _update_record(*args) - if should_record_timestamps? + def _update_record(*args, touch: true, **options) + if touch && should_record_timestamps? current_time = current_time_from_proper_timezone timestamp_attributes_for_update_in_model.each do |column| @@ -67,7 +67,7 @@ module ActiveRecord write_attribute(column, current_time) end end - super + super *args end def should_record_timestamps? |