Skip to content


DDC-2631: Replacing object in a OneToOne with OrphanRemoval=true isn't working as expected #3365

doctrinebot opened this Issue · 0 comments

2 participants


Jira issue originally created by user guaycuru:

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

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.