T
T
tukreb2020-10-05 04:05:19
symfony
tukreb, 2020-10-05 04:05:19

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();


With this code, doctrine first tries to execute:
$newipAddressPrimary->getIpAddressAssigned()->setPrimary();


Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question