Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-137

Only last relation id updated with multiple one-to-one self-referencing relations

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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).

        Activity

        Hide
        Roman S. Borschel added a comment -

        Thanks, should be fixed now.

        Show
        Roman S. Borschel added a comment - Thanks, should be fixed now.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Reinier Kip
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: