Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure
none
constraint scopes don’t trigger a query
#47800 refactored how `Relation#none` worked, and one side effect of this change was that if you had an association like this: `has_many :comments_none, ->(post) { none }, class_name: "Comment”` reading the association caused a query to happen, despite the `none` in the passed in scope. As it turns out, this is because the association performs a merge of the two scopes, and the `@none` instance variable wasn’t getting copied over to the merged scope, so the upfront guard clause checking `@none` in `#exec_main_query`. Updating the `Merger` object to add a check for null relations and call `none!` ensures the query doesn’t run in this particular scenario.
- Loading branch information