SimpleObjectHydrator: skip unsuit custom type before convert it#8566
Conversation
1e1c51f to
a2a02cd
Compare
|
I have repaired the test suite, let's try this again. |
| [ | ||
| 'p__id' => '1', | ||
| 'm__type' => 'type field', | ||
| 'e__type' => 'type field', |
There was a problem hiding this comment.
To make sure I understand the PR: here we have a field with an incorrect value in the result set, but since we are going to build a manager object, this field should not even be examined, is that correct?
If yes, why is that field even present in the result set in the first place? And why does it have a value instead of something like null? It make no sense for a manager to have the employee type field filled in, right?
There was a problem hiding this comment.
If there is a statement like this:
SELECT p0.id AS id_1,
p0.type AS type_2,
p0.type AS type_3,
p0.type AS type_4
FROM person p0
WHERE p0.discr IN ('person', 'manager', 'employee');In result set mapping will appear:
$fieldMappings = [
'type_2' => 'type',
'type_3' => 'type',
'type_4' => 'type',
];So field has a value because there is only one column that has different types for different entities, and that's why it's not null.
There was a problem hiding this comment.
@tweet9ra please don't mark conversations you did not open as resolved, what if I didn't understand the comment above?
@toshksenof thanks for your comment, I will try to understand it later, right now I'm a bit too tired for that I'm afraid. Or maybe the people I have added as reviewers will beat me to it.
There was a problem hiding this comment.
After a good night's sleep, I think I finally got it:
Doctrine will select the same column several times, one for each mapping in each subclass.
a2a02cd to
47bbc62
Compare
SimpleObjectHydrator tries to convert the value, and only then checks if we need it. This results in an error if our custom type does not get expected data to initialize php value.
47bbc62 to
2e499d8
Compare
|
@greg0ire, hi! any updates? |
|
I squash merged with a commit message that contains a more complete explanation, thanks to you both! |
SimpleObjectHydrator tries to convert the value, and only then checks if we need it.
This results in an error if our custom type does not get expected data to initialize php value.