Forms 使用映射列表以symfony(推进)形式保存时无法执行insert语句
在doSave()函数的表单中,我试图保存文章类别(它是树中的一个节点),然后将文章分配给这个类别(多对多关系)。 我在Forms 使用映射列表以symfony(推进)形式保存时无法执行insert语句,forms,symfony1,many-to-many,propel,Forms,Symfony1,Many To Many,Propel,在doSave()函数的表单中,我试图保存文章类别(它是树中的一个节点),然后将文章分配给这个类别(多对多关系)。 我在$this->saveWaArticleNewsCategoryMapList($con)中遇到错误行。(项目基于symfony 1.4.16)将文章分配到现有类别时没有错误。 public function doSave($con = null) { $scope = $this->getValue('tree_scope'); $toEdit = $this->
$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);
}
更新对象中的ArticleCategoryId
解决了以下问题:
$node->save($con);
$this->getObject()->setArticleCategoryId($node->getArticleCategoryId());
...
$node->save($con);
$this->getObject()->setArticleCategoryId($node->getArticleCategoryId());
...