Use a self-join for UPDATE with outer joins#1323
Merged
aidanharan merged 2 commits intomainfrom Apr 3, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
A port of Rails changes to support UPDATE statements with self-joins for outer joins on MSSQL.
- Update the UPDATE syntax to include an alias for the target table.
- Refactor join injection logic and the prepare_update_statement method to add a self-join.
Comments suppressed due to low confidence (2)
lib/arel/visitors/sqlserver.rb:43
- [nitpick] The alias '__active_record_update_alias' is introduced here, but later in prepare_update_statement the alias is not applied. Consider clarifying the alias usage for consistency between the UPDATE syntax and the self-join approach.
# UPDATE t1 AS __active_record_update_alias
lib/arel/visitors/sqlserver.rb:71
- Prepending the target table to the join sources may affect join ordering. Validate that this reordering does not interfere with other parts of the query processing that rely on a specific join sequence.
stmt.relation.right = [stmt.relation.left, *stmt.relation.right]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of rails/rails#54722 for MSSQL
Fix following tests from CI run https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/runs/14035778078/job/39293342462