Skip to content

Commit

Permalink
Handle insert returning using symbol
Browse files Browse the repository at this point in the history
Support using symbol for returning. Eg: "Book.insert!({ name: book_name }, returning: :id)"
  • Loading branch information
aidanharan committed Sep 27, 2024
1 parent 0761353 commit 959ef0e
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ def build_insert_sql(insert) # :nodoc:
sql = +"INSERT #{insert.into}"

if returning = insert.send(:insert_all).returning
returning_sql = if returning.is_a?(String)
returning
else
returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
end
returning_sql = Array(returning).map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
sql << " OUTPUT #{returning_sql}"
end

Expand Down

0 comments on commit 959ef0e

Please sign in to comment.