Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1640

Actual classMetadata is not used when entity with DiscriminatorMap is hydrated, instead AbstractClass metaData is used.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Because the className changes in ObjectHydrator:226 it might be that the ClassMetadata has not been loaded yet.
      When the classMetadata has not been loaded the PostLoad events are not executed.

      adding the following after the className has changed solves the issue.

      $this->_getClassMetadata($className);
      

      example:

      Class Session {
          /**
           * @access private
           * @var ArrayCollection
           * @ORM\OneToMany(targetEntity="AbstractService", mappedBy="session")
           */
          public $services;
      }
      
      /**
       * @ORM\Entity
       * @ORM\HasLifecycleCallbacks
       * @ORM\InheritanceType("SINGLE_TABLE")
       * @ORM\DiscriminatorColumn(name="type", type="string")
       * @ORM\DiscriminatorMap({
       * 		"A" = "ServiceA",
       * 		"B" = "ServiceB"
       * })
       */
      abstract class AbstractService 
      {
          /**
           * @access private
           * @var string
           * @ORM\Column()
           */
          private $_status;
      
          public $status;
      
          /**
           * @access public
           * @internal Do not use; this is for Doctrine only
           * @ORM\PostLoad
           * @return void
           */
          public function _reconstituteValueObjects()
          {
              $this->status = new Status($this->_status);
          }
      }
      
      

      When I would do now:

      foreach ( $session->services as $service ) {
          $service->status->stop();
      }
      

      $service would be a concrete class ServceA or ServiceB, but these ClassMetadata's might not be loaded yet. If this is the cause then $service->status will be null as the @PostLoad has not been executed.

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jelte Steijaert
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: