mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Versioning doesn't work with a custom type primary key #5118
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ngrevet on GitHub (Apr 29, 2016).
I've been wondering for a while why does Doctrine resets my
@Versionentity field to0every time I flush to the database even though the correct version can be found in the database, so I decided to dig down into the entrails of Doctrine and found some peculiar issue.When the execution flow reaches the
Doctrine\ORM\Persisters\Entity\BasicEntityPersister::fetchVersionValuemethod (it's the point after the flush where Doctrine tries to retrieve the new version of the entity from the database to re-hydrate the entity) apparently it assumes that the primary key for this table is a known primitive type and doesn't bother trying to map it to anything. More specifically this line:The third and fourth parameters of
fetchColumnshould be0and the type(s) of the$flatIdfield(s). But nothing is sent. In my situation, my primary key is a custom typeuuid_binary. Then down the line when you get toDoctrine\DBAL\Connection::executeQueryand the statement is being prepared, since there is no types involved in the$typesparameter, the binding actually never happens!Which means that the versioning query...
... doesn't ever receive any value for the
primarykeyplaceholder and the request ultimately fails and returnsfalse. Doctrine then takes thisfalseand assigns it to the@Versionfield of the entity inDoctrine\ORM\Persisters\Entity\BasicEntityPersister::assignDefaultVersionValue, which then translates to0.So it seems like this scenario is entirely missing.
@ngrevet commented on GitHub (Apr 29, 2016):
This fix works:
@alle commented on GitHub (Jun 3, 2017):
Yes, mate, gg! Why don't you make a PR?
@ngrevet commented on GitHub (Jun 5, 2017):
Thanks, I'm not well versed in PR on open source projects, I figured someone would probably end up using that work eventually.