Make OR more permissive, let folks write wrong queries if they want to #25495
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.
Summary
I was trying to port some old code that used or_chain, and wanted to use ActiveRecord::Relation#or instead. However, I quickly ran aground, because whereas or_chain doesn't try to protect me from stupidity, the new ActiveRecord::Relation#or code does.
The real world use case was I have a UI that lets a user select from a bunch of named scopes, which I then join together like this:
Some of those scopes eager_load associations and have restrictions on them, and currently that's not allowed.
The patch simply removes some of the restrictions on joining and including other tables, and lets me make my own mistakes. I know that it can generate unintentionally valid but wrong sql, but that's so much better than using "#to_sql" and stitching the SQL together manually.
Here's a gist about spammy cat videos showing before and after the change, with failing/passing tests.
Other Information
There was a discussion over here about it, although that was more of a complaint about the docs.