フォームのdoSave()関数で、記事カテゴリ(ツリー内のノード)を保存してから、このカテゴリの記事(多対多の関係)に割り当てようとしています。並んでいるときにエラーが発生します$this->saveWaArticleNewsCategoryMapList($con);
。(プロジェクトはsymfony 1.4.16に基づいて構築されています)。記事を既存のカテゴリに割り当ててもエラーはありません。
public function doSave($con = null) {
$scope = $this->getValue('tree_scope');
$toEdit = $this->getObject();
if ($toEdit->isNew()) {
$node = new ArticleCategory();
$node->setBrandId($this->getValue('brand_id'));
$node->setName($this->getValue('name'));
$node->setTreeScope($scope);
$root = ArticleCategoryQuery::create()->findRoot($scope);
if ($root == null) {
$root = new ArticleCategory();
$root->setName('Root');
$root->setTreeScopeIdValue($scope);
$root->makeRoot();
$root->save($con);
$node->insertAsLastChildOf($root);
$node->save($con);
return;
}
$parent = ArticleCategoryQuery::create()->findPk($this->getValue('parent_id'));
$node->insertAsLastChildOf($parent);
} else {
$node = ArticleCategoryQuery::create()->findOneByArticleCategoryId($toEdit->getArticleCategoryId());
$node->setBrandId($this->getValue('brand_id'));
$node->setName($this->getValue('name'));
if ($toEdit->getParent()->getArticleCategoryId() != $this->getValue('parent_id')) {
$parent = ArticleCategoryQuery::create()->findPk($this->getValue('parent_id'));
$node->moveToLastChildOf($parent);
}
}
$node->save($con);
$this->saveArticleNewsCategoryMapList($con); <--Error
$this->saveArticleHelpCategoryMapList($con);
}
エラー:
Unable to execute INSERT statement [INSERT INTO `article_news_category_map` (`ARTICLE_ID`) VALUES (:p0)] [wrapped: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`projectname`.`article_news_category_map`, CONSTRAINT `article_news_category_map_FK_2` FOREIGN KEY (`category_id`) REFERENCES `article_category` (`article_category_id`) ON DELETE CASCADE)]