aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-27 23:06:35 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-08-18 09:51:20 -0300
commit5bd96de6253bf45993a80ebc235b64f72b04d902 (patch)
tree8b41e163fbafe49d7a75992134027fc564e912dd /activerecord
parent9f8852128f2ad968e15b53728bb5c9fb3ba52e3b (diff)
downloadrails-5bd96de6253bf45993a80ebc235b64f72b04d902.tar.gz
rails-5bd96de6253bf45993a80ebc235b64f72b04d902.tar.bz2
rails-5bd96de6253bf45993a80ebc235b64f72b04d902.zip
Extract nested parameter assignment to a separate method
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_assignment.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb
index a54c103476..bdd198791b 100644
--- a/activerecord/lib/active_record/attribute_assignment.rb
+++ b/activerecord/lib/active_record/attribute_assignment.rb
@@ -104,8 +104,7 @@ module ActiveRecord
end
end
- # assign any deferred nested attributes after the base attributes have been set
- nested_parameter_attributes.each { |k,v| _assign_attribute(k, v) }
+ assign_nested_parameter_attributes(nested_parameter_attributes) unless nested_parameter_attributes.empty?
assign_multiparameter_attributes(multi_parameter_attributes) unless multi_parameter_attributes.empty?
ensure
@mass_assignment_options = previous_options
@@ -133,6 +132,11 @@ module ActiveRecord
end
end
+ # Assign any deferred nested attributes after the base attributes have been set.
+ def assign_nested_parameter_attributes(pairs)
+ pairs.each { |k, v| _assign_attribute(k, v) }
+ end
+
# Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done
# by calling new on the column type or aggregation type (through composed_of) object with these parameters.
# So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
@@ -252,6 +256,5 @@ module ActiveRecord
def find_parameter_position(multiparameter_name)
multiparameter_name.scan(/\(([0-9]*).*\)/).first.first.to_i
end
-
end
end