【发布时间】:2016-07-18 09:16:31
【问题描述】:
我有以下代码。 Part 的代码列需要唯一值,所以当我remove(),然后persist() 具有相同代码值的行时会抛出错误。但是,应该首先删除该行,因此只有一个值。我必须在这些命令之间运行flush() 吗?
if ($existingPart) { # we found one
if ($existingPart->getPrice() != $part->getPrice()) { # price changed
$em->remove($existingPart); #soft-delete the old one
$em->persist($part); # persist the new part
$countUpdates++; # get number of updated entities
}
} else {
$em->persist($part); # no existing part with same code, just add new part
$count++; # get number of new commits
}
}
$em->flush();
【问题讨论】:
标签: doctrine-orm symfony