Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2631

Replacing object in a OneToOne with OrphanRemoval=true isn't working as expected

    Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      PHP 5.4

      Description

      So I have a class defined like this:

      class PhoneSettings {
      [...]

      /**

      • @OneToOne(targetEntity="Medium", cascade= {"persist", "remove"}

        , orphanRemoval=true)

      • @JoinColumn(name="medium_id", referencedColumnName="medium_id", nullable=true, onDelete="SET NULL")
        **/
        protected $medium = null;

      [...]
      }
      And class Medium has no reference to the class Settings.

      Now suppose I have a $Settings object that is already persisted and has been correctly loaded. Also suppose that the $Settings object has a $medium (that is, $Settings->medium = $OldMedium)

      Now suppose I do:

      $Settings->medium = $NewMedium;
      Where $NewMedium is a different Medium object.

      When I persist $Settings, Doctrine does delete $OldMedium from the DB, but the problem is that it also deletes $NewMedium ...

      I have tried removing onDelete="SET NULL", but then I receive a "cannot delete, constraint failed" error...

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Felipe Guaycuru
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: