Details
Description
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.
Mysql Error
/*
Error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_9D8DDB05579B502F'
*/
Models and YAML Mapping
/*
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;
}
}
Script
// 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();
Activity
Mario Knippfeld
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
orphanRemoval does not work with oneToOne. Im getting "duplicate entry" errors after replacing the oneToOne object: {code:title=Mysql Error} /* Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_9D8DDB05579B502F' */ {code} {code:title=Models and YAML Mapping} /* 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; } } {code} {code:title=Script} // 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(); {code} |
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. {code:title=Mysql Error} /* Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'UNIQ_9D8DDB05579B502F' */ {code} {code:title=Models and YAML Mapping} /* 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; } } {code} {code:title=Script} // 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(); {code} |
Benjamin Eberlei
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Can't Fix [ 7 ] |
Mario Knippfeld
made changes -
| Resolution | Can't Fix [ 7 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
Benjamin Eberlei
made changes -
| Workflow | jira [ 13471 ] | jira-feedback [ 14105 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback [ 14105 ] | jira-feedback2 [ 15969 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 15969 ] | jira-feedback3 [ 18223 ] |
Benjamin Eberlei
made changes -
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Fix Version/s | 2.3.3 [ 10329 ] | |
| Resolution | Fixed [ 1 ] |
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-1666, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
This is a necessary restriction for the internals of Doctrine to always work correctly.