Open
Conversation
This commit fixes a potential performance penalty that is paid when a one-to-many or many-to-many relation is loaded using `with()` but has no joined rows. In this scenario you effectively lose the benefits of eager loading using `with()`, as the fact the relation is empty is never set, so when accessing it later the ORM dutifully goes off and queries the DB again, setting the relation to empty if there's no rows. This change means that when a `with()` is used a default value is set (`null` for -to-one and an empty array for -to-many). It also exacerbates an edge case where if join or where conditions limit the results returned for relations loaded using `with()` to zero you can't then call the relation (via `->RelationName` or `->getRelationName()`) to get the unfiltered list. In theory this is not a defined behaviour anyway, because if any joined rows are returned they remain filtered. I'd argue that this change therefore makes this behaviour consistent regardless of whether the initial query returned joined results or not.
…lidator Adds a new `with` argument to the `exists` validator that expects an array of relation names to load as part of validation. Means its possible to eager load simple relations without needing to dip out into a custom validator. Does not support custom where conditions on relations etc, just attaching relations to an existing filter.
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.
No description provided.