Doctrine always making update query for custom Money type, even if value does not change #8983
Replies: 5 comments
-
For Ramsey\Uuid\Doctrine\UuidType and custom UuisType same things. Doctrine update uuid for all selected entities with relations
This is a problem with many requests! Update set deadlock to table |
Beta Was this translation helpful? Give feedback.
-
I fix updates for Ramsey Uuid. I create custom type with same return value in convertToPHPValue and convertToDatabaseValue |
Beta Was this translation helpful? Give feedback.
-
It is kind of expected behavior, because there is a strict comparison. There already an issue about it, somewhere. Hint: Do not call |
Beta Was this translation helpful? Give feedback.
-
i have same problem... public static function listen(Event $event): void
{
$mr = app()->getContainer()->get(ManagerRegistry::class);
$em = $mr->getManager();
$repo = $em->getRepository(Line::class);
/** @var Line[] $lines */
$lines = $repo->getLinesById([
1154,
1155,
1000,
2354,
2571,
2678,
3043,
]);
$em->clear();
foreach ($lines as $line) {
$user_line = new UserLine();
$user_line->setNumber($line);
$user_line->setAssignTime(time());
$user_line->setGlobal(0);
$user_line->setSendAvailable(true);
$user_line->setGetAvailable(false);
$user_line->setAutoAdminConfirm(false);
$user_line->setUser($event->getUser());
$user_line->setIssuer($event->getUser()->getParent());
$em->persist($user_line);
}
$em->flush();
} in this code, some update happen! (per insert / one update query!) |
Beta Was this translation helpful? Give feedback.
-
@seyedmr it seems issue with primary key and your entity. F.E. if you are using Postgres uuid type and inside entity you have property string, without proper type mapping can lead to update query after every update/insert. Maybe you need to map types and it will solve your problem: |
Beta Was this translation helpful? Give feedback.
-
I have custom Money type:
and in entity it looks like this:
and each time I'm making persist/flush doctrine sending update query even if value is the same
leads to such queries
How can avoid it??? Thank you a lot!!!
Beta Was this translation helpful? Give feedback.
All reactions