【发布时间】:2014-10-07 22:09:20
【问题描述】:
我有一个名为 Theme 的实体,它的名字不是 Id,而是应该被索引并且是唯一的:
/**
* @Entity @Table(name="themes",
* uniqueConstraints={@UniqueConstraint(name="theme_unique",columns={"name"})},
* indexes={@Index(name="theme_idx", columns={"name"})})
*/
class Theme {...}
我使用现有名称创建了一个新主题。这会产生错误,脚本停止。 我应该如何获取该错误并继续执行脚本?
function CreateTheme($newThemeName) {
//$theme = $this->FindByThemeName ( $newThemeName );
//if (! $theme) {
$theme = new Theme ();
$theme->setName ( $newThemeName );
$theme->setIsActive ( false );
$theme->setIsDefault ( false );
$this->entityManager->persist ( $theme );
$this->entityManager->flush ();
return $theme;
//} else {
// $this->error = "Error in flush was avoided (name not being unique)!";
// return null;
//}
【问题讨论】:
标签: error-handling doctrine-orm entitymanager flush