Skip to content

Loading…

DDC-2983: TCI association not getting hydrated into sql statement #3747

Open
doctrinebot opened this Issue · 1 comment

2 participants

@doctrinebot

Jira issue originally created by user machete:


/****
 * @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();
@doctrinebot

Comment created by @beberlei:

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

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.