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

        Felipe Guaycuru created issue -
        Felipe Guaycuru made changes -
        Field Original Value New Value
        Description So a 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...
        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...
        Felipe Guaycuru made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2631, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated: