Skip to content

Commit

Permalink
Limit _returning_columns_for_insert to PK for DBs with no `RETURNIN…
Browse files Browse the repository at this point in the history
…G` support
  • Loading branch information
nvasilevski committed Jan 9, 2025
1 parent da32425 commit ec1de04
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions activerecord/lib/active_record/model_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,12 @@ def columns

def _returning_columns_for_insert(connection) # :nodoc:
@_returning_columns_for_insert ||= begin
auto_populated_columns = columns.filter_map do |c|
c.name if connection.return_value_after_insert?(c)
auto_populated_columns = if connection.supports_insert_returning?
columns.filter_map do |c|
c.name if connection.return_value_after_insert?(c)
end
else # we shouldn't be trying to build a list of returning columns if db doesn't `RETURNING` statement
[]
end

auto_populated_columns.empty? ? Array(primary_key) : auto_populated_columns
Expand Down

0 comments on commit ec1de04

Please sign in to comment.