DDC-172: Cascading persists doesn't seem to work with OneToMany relationship #211

Open
opened 2026-01-22 12:30:48 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 23, 2009).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user ablock:

Given the following entities:

namespace Entities;

class Parent {
    /****
     * @OneToMany(targetEntity="Child", mappedBy="parent", cascade={"persist"})
     */
    private $children;
}

class Child {
    /****
     * @ManyToOne(targetEntity="Parent", cascade={"persist"})
     * @JoinColumn(name="parent_id", referencedColumnName="id")
     */
    private $parent;
}

And the following code:

$p = new Parent;
$em->persist($org);
$em->flush();

$c = new Child;
// This method maintains the bidirectional relationship on the application side
$p->addChild($c);

$em->clear();
$id = $p->getId();

$org = $em->find('Entities\Parent', $id);
echo count($c->getChildren());

Should output "1" but instead outputs "0"

Originally created by @doctrinebot on GitHub (Nov 23, 2009). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user ablock: Given the following entities: ``` namespace Entities; class Parent { /**** * @OneToMany(targetEntity="Child", mappedBy="parent", cascade={"persist"}) */ private $children; } class Child { /**** * @ManyToOne(targetEntity="Parent", cascade={"persist"}) * @JoinColumn(name="parent_id", referencedColumnName="id") */ private $parent; } ``` And the following code: ``` $p = new Parent; $em->persist($org); $em->flush(); $c = new Child; // This method maintains the bidirectional relationship on the application side $p->addChild($c); $em->clear(); $id = $p->getId(); $org = $em->find('Entities\Parent', $id); echo count($c->getChildren()); ``` Should output "1" but instead outputs "0"
admin added the Bug label 2026-01-22 12:30:48 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#211