Answer the question
In order to leave comments, you need to log in
How to set the order in which records are updated in a single transaction?
How can doctrine/Symfony specify the order in which the data in the database is updated in a single transaction?
The table has a uniqueness check, in which the state of the object can be only one. To change the state, you must first remove it from the old record, and then assign it to another one. But on one transaction, doctrine tries to assign the state first...
/** @var IpAddressAssigned $oldPrimaryIp */
$oldPrimaryIp = $port->getIpAddressesAssignedCollection()->filter(
function ($value, $key){
/** @var IpAddressAssigned $value */
return $value->isPrimary();})->first();
$oldPrimaryIp->setSecondary();
$newipAddressPrimary->getIpAddressAssigned()->setPrimary();
$this->em->flush();
$newipAddressPrimary->getIpAddressAssigned()->setPrimary();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question