-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Description
Jira issue originally created by user gutzuwissen:
orphanRemoval does not work with oneToOne.
Im getting "duplicate entry" errors after replacing the oneToOne object.
Doctrine seems to insert the new data before removing the old one.
if i remove the unique constraint by hand in the database it works.
/*
Error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_9D8DDB05579B502F'
*/
/*
Contact:
type: entity
table: contact
fields:
_id:
id: true
type: integer
unsigned: true
nullable: false
generator:
strategy: AUTO
column: id
oneToOne:
_standingData:
targetEntity: StandingData
mappedBy: _contact
cascade: ["persist", "merge", "remove"]
orphanRemoval: true
*/
class Contact
{
private $_id;
private $_standingData;
public function newStandingData(StandingData $sd)
{
$this->_standingData = $sd;
$sd->setContact($this);
}
}
/*
StandingData:
type: entity
table: standing_data
fields:
_id:
id: true
type: integer
unsigned: true
nullable: false
generator:
strategy: AUTO
column: id
oneToOne:
_contact:
targetEntity: Contact
inversedBy: _standingData
joinColumns:
contact_id:
referencedColumnName: id
onDelete: cascade
*/
class StandingData
{
private $_id;
private $_contact;
public function setContact(Contact $c)
{
$this->_contact = $c;
}
}
// Create new Contact
$contact = new Contact();
$contact->newStandingData(new \StandingData());
$em->persist($contact);
$em->flush();
// Try to change StandingData
$contact->newStandingData(new \StandingData());
$em->flush();
Reactions are currently unavailable