确定哪些实体导致Doctrine UniqueConstraintViolationException

时间:2017-11-01 17:38:32

标签: php doctrine

当刷新多个持续存在时,有没有办法确定负责UniqueConstraintViolationException的实体?​​

$entityManager->persist($entity1);
$entityManager->persist($entity2);
$entityManager->persist($entity3);
...

$entityManager->persist($entity100);

try {
    $entityManager->flush();
} catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
    // Which entities were responsible for the violation?
}

我很感激我可以在每次坚持后刷新,但是我正在对它们进行批处理以减少对数据库的调用。

0 个答案:

没有答案