Doctrine 1
  1. Doctrine 1
  2. DC-345

delete reference between OneToOne-Relation with synchronizeWithArray(), patch available

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: Record, Relations
    • Labels:
      None

      Description

      There is no possibility to delete a reference on a OneToOne-Relation with synchronizeWithArray().

      If User and Group would be OneToOne related, i would expect that I could do something like the following (like on ManyToMany-Relations), to delete the relation between both.

      $user->synchronizeWithArray(array(
          'Group' => array() // no error, but the relation is not deleted
      ));
      
      or
      
      $user->synchronizeWithArray(array(
          'Group' => array(null) // error, cause doctrine expects an existing ID
      ));
      

      This fixes the problem:

      Index: library/Doctrine/Record.php
      ===================================================================
      --- library/Doctrine/Record.php	(revision 6903)
      +++ library/Doctrine/Record.php	(working copy)
      @@ -2012,6 +2012,8 @@
                           if (isset($value[0]) && ! is_array($value[0])) {
                               $this->unlink($key, array(), false);
                               $this->link($key, $value, false);
      +                    } else if (empty($value) || (null === current($value))) {
      +                    	$this->unlink($key, array(), false);
                           } else {
                               $this->$key->synchronizeWithArray($value);
                           }
      

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Hmm. The second syntax is weird. I think the first syntax makes more sense, no?

        Show
        Jonathan H. Wage added a comment - Hmm. The second syntax is weird. I think the first syntax makes more sense, no?

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Marcus Häußler
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: