Repository navigation
[13.x] Fix findOrNew() and chunkMap() on HasManyThrough and BelongsToMany - #61855
Merged
taylorotwell merged 2 commits intoOct 5, 2026
Merged
Conversation
shaedrich
reviewed
Oct 3, 2026
| * @template TReturn | ||
| * | ||
| * @param callable(TRelatedModel&object{pivot: TPivotModel}): TReturn $callback | ||
| * @param int $count |
Contributor
There was a problem hiding this comment.
Passing a negative number to $count may result in
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 near "offset": syntax error (SQL: select * from "users" order by "users"."id" asc offset 0)
so it might be good to type this as
Suggested change
| * @param int $count | |
| * @param non-negative-int $count |
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.
findOrNew()onHasManyThrough/HasOneThrough, andchunkMap()on those and onBelongsToMany, are not defined on the relation, so they get forwarded to the Eloquent builder and run asselect *over the join. Columns from the intermediate or pivot table then overwrite the related model's columns.For example:
On
BelongsToMany,chunkMap()returns models withoutpivot, and if the pivot table has anidcolumn the models get the pivot row's id.This adds
findOrNew()andchunkMap()toHasOneOrManyThrough, andchunkMap()toBelongsToMany, going through the relation's ownfind()andchunk()the same wayeach()andchunk()already do (#22127).