Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2984

Support Custom DBAL types to be used as identifiers

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4, 2.4.1
    • Fix Version/s: 2.5, 2.4.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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 DDC-2176. The issue is closed and I don't understand why?

      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!

        Activity

        Show
        Guilherme Blanco added a comment - As of https://github.com/doctrine/doctrine2/commit/5ce6dabe9bb9e81eac6fd261db9bd29f7b7f290c this issue was fixed.
        Hide
        Alexander Miertsch added a comment -

        I send a pull request that reproduces the bug in a TestCase, but DoctrineBot has opened a new issue: DDC-2998.

        Show
        Alexander Miertsch added a comment - I send a pull request that reproduces the bug in a TestCase, but DoctrineBot has opened a new issue: DDC-2998 .
        Hide
        Alexander Miertsch added a comment -

        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 DDC-2176 to work with a string represantation of the VO inside the Entity.

        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): ...
        Even if the custom type implements a __toString() method.
        The error/warning occurs in the same line as of the provided code block of Yves Berkholz:

        $this->identityMap[$class->rootEntityName][$idHash] = $entity; // <- 2466 -> now it is line 2578

        Show
        Alexander Miertsch added a comment - 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 DDC-2176 to work with a string represantation of the VO inside the Entity. 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): ... Even if the custom type implements a __toString() method. The error/warning occurs in the same line as of the provided code block of Yves Berkholz: $this->identityMap [$class->rootEntityName] [$idHash] = $entity; // <- 2466 -> now it is line 2578
        Hide
        Marco Pivetta added a comment -

        DDC-2176 duplicates DDC-1998

        Some clarifications:

        • custom types work as identifiers with the ORM as long as object types implement a __toString method that emulates the unique identifier
        • value objects as identifiers are not yet supported and will likely not be supported for another while because of technical limitations

        What you can do to help out is writing a test case showing how you would want to use VOs on associations and identifiers.

        Show
        Marco Pivetta added a comment - DDC-2176 duplicates DDC-1998 Some clarifications: custom types work as identifiers with the ORM as long as object types implement a __toString method that emulates the unique identifier value objects as identifiers are not yet supported and will likely not be supported for another while because of technical limitations What you can do to help out is writing a test case showing how you would want to use VOs on associations and identifiers.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Alexander Miertsch
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: