Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def build_insert_sql(insert) # :nodoc:
returning_sql = if returning.is_a?(String)
returning
else
returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
Array(returning).map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
end
sql << " OUTPUT #{returning_sql}"
end
Expand Down
11 changes: 11 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,17 @@ def test_insert_all_returns_requested_sql_fields_coerced
result = Book.insert_all! [{ name: "Rework", author_id: 1 }], returning: Arel.sql("UPPER(INSERTED.name) as name")
assert_equal %w[ REWORK ], result.pluck("name")
end

# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
coerce_tests! :test_insert_with_type_casting_and_serialize_is_consistent
def test_insert_with_type_casting_and_serialize_is_consistent_coerced
connection.remove_index(:books, column: [:author_id, :name])

original_test_insert_with_type_casting_and_serialize_is_consistent
ensure
Book.where(author_id: nil, name: '["Array"]').delete_all
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
end
end

module ActiveRecord
Expand Down
Loading