mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Should not pass extra args to _update_record
The argument of `_update_record` and `_create_record` is `attribute_names`, that is reserved for overriding by partial writes attribute names.67e20d1d48/activerecord/lib/active_record/persistence.rb (L719)
67e20d1d48/activerecord/lib/active_record/persistence.rb (L737)
67e20d1d48/activerecord/lib/active_record/attribute_methods/dirty.rb (L171)
67e20d1d48/activerecord/lib/active_record/attribute_methods/dirty.rb (L177)
The reason that no failing with extra args is that `Timestamp` module which is most outside module of the `_update_record` discards the extra args.67e20d1d48/activerecord/lib/active_record/timestamp.rb (L104)
But that looks odd dependency. It should not be passed extra args, should only be passed attribute names.
This commit is contained in:
parent
67e20d1d48
commit
3b6602aa7a
3 changed files with 13 additions and 7 deletions
|
@ -324,7 +324,7 @@ module ActiveRecord
|
|||
|
||||
private
|
||||
|
||||
def create_or_update(*)
|
||||
def create_or_update(**)
|
||||
_run_save_callbacks { super }
|
||||
end
|
||||
|
||||
|
@ -332,7 +332,7 @@ module ActiveRecord
|
|||
_run_create_callbacks { super }
|
||||
end
|
||||
|
||||
def _update_record(*)
|
||||
def _update_record
|
||||
_run_update_callbacks { super }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -707,10 +707,10 @@ module ActiveRecord
|
|||
)
|
||||
end
|
||||
|
||||
def create_or_update(*args, &block)
|
||||
def create_or_update(**, &block)
|
||||
_raise_readonly_record_error if readonly?
|
||||
return false if destroyed?
|
||||
result = new_record? ? _create_record(&block) : _update_record(*args, &block)
|
||||
result = new_record? ? _create_record(&block) : _update_record(&block)
|
||||
result != false
|
||||
end
|
||||
|
||||
|
|
|
@ -101,8 +101,8 @@ module ActiveRecord
|
|||
super
|
||||
end
|
||||
|
||||
def _update_record(*args, touch: true, **options)
|
||||
if touch && should_record_timestamps?
|
||||
def _update_record
|
||||
if @_touch_record && should_record_timestamps?
|
||||
current_time = current_time_from_proper_timezone
|
||||
|
||||
timestamp_attributes_for_update_in_model.each do |column|
|
||||
|
@ -110,7 +110,13 @@ module ActiveRecord
|
|||
_write_attribute(column, current_time)
|
||||
end
|
||||
end
|
||||
super(*args)
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def create_or_update(touch: true, **)
|
||||
@_touch_record = touch
|
||||
super
|
||||
end
|
||||
|
||||
def should_record_timestamps?
|
||||
|
|
Loading…
Reference in a new issue