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
|
@ -254,9 +254,9 @@ class ActiveRecord::Base
|
|||
# +options+.
|
||||
def import_without_validations_or_callbacks( column_names, array_of_attributes, options={} )
|
||||
columns = column_names.map { |name| columns_hash[name.to_s] }
|
||||
|
||||
|
||||
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?
|
||||
number_inserted = 0
|
||||
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+
|
||||
# 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|
|
||||
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)
|
||||
else
|
||||
connection.quote(val, columns[j])
|
||||
|
|
Loading…
Reference in a new issue