I have an unidirectional oneToOne relationship between a Person and User. I am trying to execute method mergePeople.
public function mergePeople($personA, $personB)
{
//...
$personB->setUser($personA->getUser());
$personA->setUser(NULL);
$this->em->remove($personA);
$this->em->flush();
}
But this code throws an exception:
An exception occurred while executing 'UPDATE person SET last_name = ?, user_id = ? WHERE id = ?' with params ["Sanchez", 298, 47]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '298' for key 'UNIQ_6F549197A76ED395'
I am wondering why I get this error. Is it some kind of bug(in my code or somewhere else) or doctrine doesn't handle this situation normally(should firstly flush setUser(NULL) change and then other changes)?
Hi everyone,
I have an unidirectional oneToOne relationship between a Person and User. I am trying to execute method mergePeople.
But this code throws an exception:
I am wondering why I get this error. Is it some kind of bug(in my code or somewhere else) or doctrine doesn't handle this situation normally(should firstly flush
setUser(NULL)
change and then other changes)?doctrine/orm 2.4.8
doctrine/dbal 2.4.5
Symfony doctrine2 bundle 1.6.2