Skip to content

Commit 61f170c

Browse files
committed
Fix upsert error on repeated timestamps
Ref: rails/rails#55960
1 parent e0f34c3 commit 61f170c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def joining_on_columns_with_uniqueness_constraints(columns_with_uniqueness_const
649649
# however, since we need to have "target." for the assignment, we also generate the CASE switch ourselves
650650
def build_sql_for_recording_timestamps_when_updating(insert:)
651651
insert.model.timestamp_attributes_for_update_in_model.filter_map do |column_name|
652-
if insert.send(:touch_timestamp_attribute?, column_name)
652+
if insert.send(:touch_timestamp_attribute?, column_name) && !column_name.to_sym.in?(insert.send(:insert_all).updatable_columns)
653653
"target.#{quote_column_name(column_name)}=CASE WHEN (#{insert.updatable_columns.map { |column| "(source.#{quote_column_name(column)} = target.#{quote_column_name(column)} OR (source.#{quote_column_name(column)} IS NULL AND target.#{quote_column_name(column)} IS NULL))" }.join(" AND ")}) THEN target.#{quote_column_name(column_name)} ELSE #{high_precision_current_timestamp} END,"
654654
end
655655
end.join

0 commit comments

Comments
 (0)