1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Only dup attributes in activerecord attribute_assignment

This commit is contained in:
Vinicius Stock 2020-02-06 17:02:56 -05:00
parent 8b59960cd4
commit 112c3ec0f5
No known key found for this signature in database
GPG key ID: 1A3EC85374C0969A
2 changed files with 6 additions and 5 deletions

View file

@ -31,7 +31,7 @@ module ActiveModel
end
return if new_attributes.empty?
_assign_attributes(sanitize_for_mass_assignment(new_attributes.dup))
_assign_attributes(sanitize_for_mass_assignment(new_attributes))
end
alias attributes= assign_attributes

View file

@ -10,17 +10,18 @@ module ActiveRecord
def _assign_attributes(attributes)
multi_parameter_attributes = {}
nested_parameter_attributes = {}
new_attributes = attributes.dup
attributes.each do |k, v|
new_attributes.each do |k, v|
key = k.to_s
if key.include?("(")
multi_parameter_attributes[key] = attributes.delete(k)
multi_parameter_attributes[key] = new_attributes.delete(k)
elsif v.is_a?(Hash)
nested_parameter_attributes[key] = attributes.delete(k)
nested_parameter_attributes[key] = new_attributes.delete(k)
end
end
super(attributes)
super(new_attributes)
assign_nested_parameter_attributes(nested_parameter_attributes) unless nested_parameter_attributes.empty?
assign_multiparameter_attributes(multi_parameter_attributes) unless multi_parameter_attributes.empty?