Repository navigation
Load @with relations onto every instance of a duplicated row - #2807
Open
liliangiraudo5 wants to merge 2 commits into
Open
liliangiraudo5 wants to merge 2 commits into
liliangiraudo5 wants to merge 2 commits into
Conversation
RelationBatchLoader kept one parent per model key, so when the same row was hydrated into two instances under one path (e.g. a belongsToMany with two pivot rows to the same model), only the last instance got the relation. @with and @withCount then ran the field resolver on an instance without it: a lazy load per duplicate, or a missing *_count attribute. The paginated loader dedupes its UNION subqueries by model key, so it still runs one subquery per row.
Copilot stopped reviewing on behalf of
spawnia due to an error
October 25, 2026 12:22
Collaborator
|
🤖 @liliangiraudo5 #2803 fixes the same bug differently: I lean towards your approach, since it fixes the batch loader for every caller. |
1 of 2 tasks
# Conflicts: # src/Execution/ModelsLoader/PaginatedModelsLoader.php
Author
|
Yes, #2803 would fix our case too, but I agree fixing the batch loader is better. Thanks for merging master in, nothing else to change on my side. |
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.
Changes
RelationBatchLoader::load()keyed parents byModelKey, so a second instance of the same row under one path replaced the first, and only the surviving instance got the relation.RelationDirectivereturns the batch result by key and is unaffected.@withand@withCountrun the field resolver on their own$parent, which never got the relation.With a
belongsToManyholding two pivot rows to the same model, that means a lazy load per duplicate (LazyLoadingViolationExceptionunderModel::preventLazyLoading()), or a missing*_countattribute.The same instance reached twice (e.g. a shared
belongsTo) is still loaded once.Breaking changes
None. No
@apisurface changes;RelationBatchLoader::$parentsis now keyed by object id.Changelog
Fixed
@withand@withCountrelations onto every instance of a model that is hydrated more than once under the same path, e.g. through duplicate pivot rows