我有以下代码。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();https://stackoverflow.com/questions/38432873
复制相似问题