Allow Partial for Non-Object Hydration #1
+10
−5
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.
As mentioned here we can understand partial object hydration is a bad idea that can lead to many issues. So it seems a fine to not support it anymore.
But it's also mentionned that the partial object problem does not apply to methods or queries where you do not retrieve the query result as objects. Examples are: Query#getArrayResult(), Query#getScalarResult(), Query#getSingleScalarResult(), etc.
While trying to update code in a project using partial and array result hydration, for performance reasons, my code is way less clean using Dto (that are always flat objects) or using the mix object and scalar data.
Ex. using partial to get an entity with metadata of file attached.
Result:
Using a Dto, it's not possible to create nested objects like that:
I receive an error
[Syntax Error] line 0, col 53: Error: Unexpected 'new'
as nested objects are not supported.Using a flat Dto:
I need to type
publications
as int rather thanCollection
orarray
else I receive an error.Result:
Please note that the objects are duplicated because I have a collection of publication. It's would expect to receive a collection or array of publications here.
Using a mix of object and scalar in query:
I need to name the scalar fields explicitly to avoid ambiguity when fetching data. I also have a multi level root result which seems not as clean as with partial query.
Result:
Here is just one of multiple sample I have in mind. Could you please reconsider the support of partial for non problematic use cases? Thanks
Related commit: doctrine#8471