Honor primary_key option in $belongs_to and $has_many when eager loading#578
Open
xak2000 wants to merge 3 commits intojpfuentes2:masterfrom
Open
Honor primary_key option in $belongs_to and $has_many when eager loading#578xak2000 wants to merge 3 commits intojpfuentes2:masterfrom
xak2000 wants to merge 3 commits intojpfuentes2:masterfrom
Conversation
Before this change, some eager loaded nested relationships were wiped out when some first-level relationships were the same model object. For example, when 2 `Post`s have the same `Author` and you load posts with option `'include' => ['author' => ['profile']]`, then first loaded post will have eager loaded author with eager loaded profile, while the second post will have eager loaded author (cloned), but without eager loaded profile. `clone` method just doesn't clone the relationships of cloned author. This leads to a serious performance degradation. Because you expect all relationships are eagerly loaded when traverse them in the code, while in reality only some of them are loaded, and others generate many unnecessary SQL queries to load them on-the-fly. After this change, nested relationships will be cloned recursively instead of wiping them out completely. This leads to expected behavior, when all eagerly loaded relationships will be preserved and fixes the performance degradation.
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.
Fixes #364, #366.
This pull request has changes equal to #365 and #368, but includes tests to prove the changes works.