[11.x] Pass collection of models to whereMorphedTo / whereNotMorphedTo#54324
Merged
taylorotwell merged 4 commits intoJan 24, 2025
Merged
Conversation
owenvoke
reviewed
Mar 4, 2025
| $models->groupBy(fn ($model) => $model->getMorphClass())->each(function ($models) use ($query, $relation) { | ||
| $query->orWhere(function ($query) use ($relation, $models) { | ||
| $query->where($relation->qualifyColumn($relation->getMorphType()), '<=>', $models->first()->getMorphClass()) | ||
| ->whereNotIn($relation->qualifyColumn($relation->getForeignKeyName()), $models->map->getKey()); |
Contributor
There was a problem hiding this comment.
@gdebrauwer, should this be changed to whereIn() as it's negating a negative at the moment? 🤔 We are experiencing issues with whereNotMorphedTo() on upgrading to 11.40.x
Here's a comparison of the differences:
# Previous logic (`<11.40`)
select *
from `posts`
where not (`posts`.`author_type` <=> 'user' and `posts`.`author_id` <=> 1);
# Current logic (`>=11.40`)
select *
from `posts`
where not ((`posts`.`author_type` <=> 'user' and `posts`.`author_id` not in (1)));
# Updated logic (with `whereIn()`), this logic more aligns with the previous logic
select *
from `posts`
where not ((`posts`.`author_type` <=> 'user' and `posts`.`author_id` in (1)));I've opened a PR here: #54902
1 task
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.
The
whereBelongsTomethod supports providing a collection of models. This PR adds that behavior to thewhereMorphedTo(andwhereNotMorphedTo) methodIt also supports providing a collection with different kinds of models: