Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate inconsistent behavior that merging conditions on the same c…
…olumn Related to #39250 and #39236. The purpose of the change here is to unify inconsistent behavior on the merging. For now, mergee side condition is replaced by merger side condition only if both arel nodes are Equality or In clauses. In other words, if mergee side condition is not Equality or In clauses (e.g. `between`, `or`, `gt`, `lt`, etc), those conditions will be kept even on the same column. This behavior is harder to predict unless people are familiar with the merging behavior. Originally I suppose this behavior is just an implementation issue rather than an intended one, since `unscope` and `rewhere`, which were introduced later than `merge`, works more consistently. Since most of the conditions are usually Equality and In clauses, I don't suppose most people have encountered this merging issue, but I'd like to deprecate the inconsistent behavior and will completely unify that to improve a future UX. ```ruby # Rails 6.1 (IN clause is replaced by merger side equality condition) Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob] # Rails 6.1 (both conflict conditions exists, deprecated) Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [] # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob] # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced) Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob] Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob] ```
- Loading branch information
Showing
3 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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