Fix regression in 2.7.1 when mysqli
is used with discriminator column that is not a string
#8055
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.
In 2.7.1, #7974 was included as the fix for #7505. Basically, the change made was that when hydrating entities with inheritance, only the fields/data that belong to the particular inheritance type must be passed to
UoW::createEntity()
.To do so, the
SimpleObjectHydrator
will compare the discriminator column value against the list of known types/mappings.orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php
Lines 140 to 143 in 9273057
While the descriminator types in
$cacheKeyInfo['discriminatorValues']
are always strings, the actual$discrColumnValue
may be anint
, at least when the discriminator column is defined as int and themysqli
driver is used.The problem seems not to occur with
pdo_mysql
: In that case, the values returned from the result set/query are (always?) strings.My suggested fix is to
(string)
cast the discriminator value, as it already happens in theAbstractHydrator
:orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Lines 300 to 306 in 9273057
Update:
It seems Travis is running MySQL tests with
pdo_mysql
only, so the test case does not even show the issue. I am also sure that the issue would have surfaced with the existing tests.I still believe the fix is correct, given the similarity to the code in
AbstractHydrator
.Anyway, could someone advise if this
pdo_mysql
/mysqli
discrepancy is something worth looking into?