Skip to content

Commit 8bd31c2

Browse files
authored
Handle insert returning using symbol (#1226)
1 parent 78c2079 commit 8bd31c2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def build_insert_sql(insert) # :nodoc:
145145
returning_sql = if returning.is_a?(String)
146146
returning
147147
else
148-
returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
148+
Array(returning).map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
149149
end
150150
sql << " OUTPUT #{returning_sql}"
151151
end

test/cases/coerced_tests.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,17 @@ def test_insert_all_returns_requested_sql_fields_coerced
24872487
result = Book.insert_all! [{ name: "Rework", author_id: 1 }], returning: Arel.sql("UPPER(INSERTED.name) as name")
24882488
assert_equal %w[ REWORK ], result.pluck("name")
24892489
end
2490+
2491+
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
2492+
coerce_tests! :test_insert_with_type_casting_and_serialize_is_consistent
2493+
def test_insert_with_type_casting_and_serialize_is_consistent_coerced
2494+
connection.remove_index(:books, column: [:author_id, :name])
2495+
2496+
original_test_insert_with_type_casting_and_serialize_is_consistent
2497+
ensure
2498+
Book.where(author_id: nil, name: '["Array"]').delete_all
2499+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2500+
end
24902501
end
24912502

24922503
module ActiveRecord

0 commit comments

Comments
 (0)