Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2983

TCI association not getting hydrated into sql statement

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      MySQL, using DoctrineORMModule (zf2 integration)

      Description

      
      /**
       * @ORM\Entity
       * @ORM\Table(name="base")
       * @ORM\InheritanceType("JOINED")
       * @ORM\DiscriminatorColumn(name="discriminator", type="string")
       * @ORM\DiscriminatorMap({
       * "a" = "A",
       * "b" = "B",
       * })
       */
      class Base
      {
          /**
           * @ORM\Id
           * @ORM\Column(type="integer")
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          protected $id;
      }
      
      /**
       * @ORM\Entity
      **/
      class A extends Base {
          /**
           * @ORM\ManyToOne(targetEntity="B", inversedBy="as")
           */
          protected $b;
      
          /**
           * @ORM\OneToMany(targetEntity="C", cascade={"persist"})
           */
          protected $cs;
      }
      
      /**
       * @ORM\Entity
      **/
      class B Extends Base {
          /**
           * @ORM\OneToMany(targetEntity="A", mappedBy="b")
           */
          protected $as;
      }
      
      /**
       * @ORM\Entity
      **/
      class C {
        // ...
      }
      

      Doing this:

      $a = new A();
      $b = new B();
      
      $a->setB($b);
      $b->addA($a);
      
      var_dump($a->getB()); // outputs B (b not null!)
      var_dump($b->getAs()) // outputs A (private $_elements => [0] class B)
      
      $em->persist($a);
      $em->persist($b);
      $em->flush();
      
      

      Leads to

      integrity constraint violation, b_id can not be null

      aka

      INSERT INTO a (id, b_id), (123, null);

      I have no idea why this happens. This works:

      $a = new A();
      $b = new B();
      
      $a->setB($b);
      $b->addA($a);
      
      var_dump($a->getB()); // outputs B (b not null!)
      var_dump($b->getAs()) // outputs A (private $_elements => [0] class B)
      
      $em->persist($a);
      $em->flush();
      $em->persist($b);
      $em->flush();
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This most likely happens because the UnitOfWork tries to set the owner and reverse incorrectly due to an ordering issue.

        Show
        Benjamin Eberlei added a comment - This most likely happens because the UnitOfWork tries to set the owner and reverse incorrectly due to an ordering issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Machete
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: