Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2704

When using Discriminator EntityManager#merge fails

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I have the following hierarchy:

      • AgentConfig has relation ManyToOne with AgentTask.
      • AgentTask has DiscriminatorColumn & DiscriminatorMap assigned to it.
      • AgentTask has relation ManyToOne with AgentTaskConfig.

      I believe the problem is because of the following:

      UnitOfWork#doMerge has the tries to get properties the following way:

      // Merge state of $entity into existing (managed) entity
      foreach ($class->reflClass->getProperties() as $prop) {
      

      This obviously doesn't get the parent class (AgentTask) properties.

      Later on UnitOfWork fails on line:

      $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);
      

      because $prevManagedCopy doesn't have properties set from entity.

      My proposal is to get the properties the following way:

      $properties = $class->reflClass->getProperties();
      $parent = $class->reflClass;
      while (($parent = $parent->getParentClass()) != null) {
          $properties = array_merge($parent->getProperties(), $properties);
      }
      
      // Merge state of $entity into existing (managed) entity
      foreach ($properties as $prop) {
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Vladyslav Petrovych
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: