Fix prepareQueryOrNewObj with object values #2189
Merged
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.
Summary
Following #2104.
In API Platform, since the release of the 2.1 version, the following test was failing: https://github.com/api-platform/core/blob/d83d50228e2686b7a2f76bfbadf2dec3fd83fdcd/tests/Bridge/Doctrine/MongoDbOdm/Filter/DateFilterTest.php#L264-L289
You can see it here: https://github.com/api-platform/core/pull/3571/checks?check_run_id=718581504 and here: https://github.com/api-platform/core/pull/3571/checks?check_run_id=718581453.
It's because #2104 has removed the
array_map
on the$preparedValue
:DateTime
is not converted anymore to the DB type if it is the type of a value in an array and if the field is not present in the class (for instance with a lookup).To fix this, I've changed the
convertToDatabaseValue
to fallback toType::convertPHPToDatabaseValue
if the field doesn't have a mapping.It's also a better behavior than the previous one (before #2104): the previous one didn't work if the value was too deep nested.