Fix that values_sql_for_attributes wasn't accessing the columns with the same indexes as the array_of_attributes, and so was sometime mismatched.
Also return to the column_names[j] == primary_key style of testing, as the column itself is not always present
This commit is contained in:
parent
df75eea4db
commit
7bd0e2693a
|
@ -256,7 +256,7 @@ class ActiveRecord::Base
|
||||||
columns = column_names.map { |name| columns_hash[name.to_s] }
|
columns = column_names.map { |name| columns_hash[name.to_s] }
|
||||||
|
|
||||||
columns_sql = "(#{column_names.map{|name| connection.quote_column_name(name) }.join(',')})"
|
columns_sql = "(#{column_names.map{|name| connection.quote_column_name(name) }.join(',')})"
|
||||||
values_sql = values_sql_for_attributes(array_of_attributes)
|
values_sql = values_sql_for_column_names_and_attributes(column_names, array_of_attributes)
|
||||||
if not supports_import?
|
if not supports_import?
|
||||||
number_inserted = 0
|
number_inserted = 0
|
||||||
values_sql.each do |values|
|
values_sql.each do |values|
|
||||||
|
@ -280,10 +280,12 @@ class ActiveRecord::Base
|
||||||
|
|
||||||
# Returns SQL the VALUES for an INSERT statement given the passed in +columns+
|
# Returns SQL the VALUES for an INSERT statement given the passed in +columns+
|
||||||
# and +array_of_attributes+.
|
# and +array_of_attributes+.
|
||||||
def values_sql_for_attributes(array_of_attributes ) # :nodoc:
|
def values_sql_for_column_names_and_attributes(column_names, array_of_attributes) # :nodoc:
|
||||||
|
columns = column_names.map { |name| columns_hash[name.to_s] }
|
||||||
|
|
||||||
array_of_attributes.map do |arr|
|
array_of_attributes.map do |arr|
|
||||||
my_values = arr.each_with_index.map do |val,j|
|
my_values = arr.each_with_index.map do |val,j|
|
||||||
if !sequence_name.blank? && columns[j].primary && val.nil?
|
if !sequence_name.blank? && column_names[j] == primary_key && val.nil?
|
||||||
connection.next_value_for_sequence(sequence_name)
|
connection.next_value_for_sequence(sequence_name)
|
||||||
else
|
else
|
||||||
connection.quote(val, columns[j])
|
connection.quote(val, columns[j])
|
||||||
|
|
Loading…
Reference in a new issue