[DDC-2984] Support Custom DBAL types to be used as identifiers Created: 15/Feb/14 Updated: 16/Apr/14 Resolved: 16/Apr/14
|Project:||Doctrine 2 - ORM|
|Affects Version/s:||2.4, 2.4.1|
|Fix Version/s:||2.5, 2.4.3|
|Reporter:||Alexander Miertsch||Assignee:||Guilherme Blanco|
I've tried to use a Value Object that extends the DBAL\Types\StringType as identifier of an Aggregate Root. This is common practice in DDD, f.e. defining a TrackingId as identifier of a Cargo Aggregate. I've written a unit test for my repository and everything seemed to work well until clearing the UnitOfWork and trying to fetch a fresh entity. The error is similar to the one described in
I think the support of Value Objects is a must have in Doctrine. I've checked out the new feature of defining embedded Value Objects and it works as a charm. But without the option to use Value Objects as identifiers Doctrine is missing an important feature!
|Comment by Marco Pivetta [ 15/Feb/14 ]|
What you can do to help out is writing a test case showing how you would want to use VOs on associations and identifiers.
|Comment by Alexander Miertsch [ 16/Feb/14 ]|
thank you for your reply. I have to check with my client if I can spend time to provide a test case. For now, we use the workaround that Yves Berkholz mentioned in his issue
The problem is, that the UnitOfWork uses the $idHash as key in the identityMap. If you use a Custom DBAL type as Identifier, the $idHash will be an Object and PHPUnit fails with the error: PHPUnit_Framework_Error_Warning : Illegal offset type in Doctrine\ORM\UnitOfWork.php(2578): ...
$this->identityMap[$class->rootEntityName][$idHash] = $entity; // <- 2466 -> now it is line 2578
|Comment by Alexander Miertsch [ 24/Feb/14 ]|
I send a pull request that reproduces the bug in a TestCase, but DoctrineBot has opened a new issue:
|Comment by Guilherme Blanco [ 16/Apr/14 ]|
As of https://github.com/doctrine/doctrine2/commit/5ce6dabe9bb9e81eac6fd261db9bd29f7b7f290c this issue was fixed.