DDC-137: Only last relation id updated with multiple one-to-one self-referencing relations #1989

Closed
doctrinebot opened this Issue Nov 12, 2009 · 2 comments

1 participant

@doctrinebot

Jira issue originally created by user reinier.kip:

Take this simplified situation:

/*** @Entity **/
class Entity {
    /*** @Id @GeneratedValue(strategy="AUTO") @Column(type="integer") **/
    public $id;

    /****
     * @OneToOne(targetEntity="Entity", cascade={"persist"})
     * @JoinColumn(name="other1", referencedColumnName="id")
     */
    public $other1;

    /****
     * @OneToOne(targetEntity="Entity", cascade={"persist"})
     * @JoinColumn(name="other2", referencedColumnName="id")
     */
    public $other2;
}

$entity1 = new Entity();
$em->persist($entity1);
$entity1->other1 = $entity2 = new Entity();
$entity1->other2 = $entity3 = new Entity();
$em->flush();

The entities' ids are now:
Entity 1: 1, Entity 2: 2, Entity 3: 3

However, the other1's relation id is not updated:

id  other1  other2
1   NULL    3:  // other1's id is missing
2   NULL    NULL
3   NULL    NULL

The SQL clarifies:

INSERT INTO Entity (other1, other2) VALUES (?, ?)
array(2) {
  [1]=>
  NULL
  [2]=>
  NULL
}
INSERT INTO Entity (other1, other2) VALUES (?, ?)
array(2) {
  [1]=>
  NULL
  [2]=>
  NULL
}
INSERT INTO Entity (other1, other2) VALUES (?, ?)
array(2) {
  [1]=>
  NULL
  [2]=>
  NULL
}
UPDATE Entity SET other2 = ? WHERE id = ?
array(2) {
  [0]=>
  int(3)
  [1]=>
  int(1)
}

Adding 'other3' proved that only the last relation id is updated, as such:

id  other1  other2  other3
1   NULL    NULL    4   // other1 and other2 missing
2   NULL    NULL    NULL
3   NULL    NULL    NULL
4   NULL    NULL    NULL

This is not the case with relations that reference to entities outside the class hierarchy (so the same problem occurs with relations inside the class hierarchy).

@doctrinebot

Comment created by romanb:

Thanks, should be fixed now.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment