0
我在SYmfony2上做了一個簡單的Blog引擎。關係ManyToOne - 我的實體無法識別的字段
我有2個實體評論和文章誰是與ManyToOne評論方面有關。
// Comment.php
/**
* @ORM\ManyToOne(targetEntity="Am\BlogBundle\Entity\Article")
* @ORM\JoinColumn(nullable=false)
*/
private $article;
當我嘗試刪除文章時,我想刪除與本文相關的所有評論。
//Am/BlogBundle/Controller/BlogController.php
public function delArticleAction(Article $article)
{
$em = $this->getDoctrine()
->getEntityManager();
$list_tags = $em->getRepository('AmBlogBundle:Tag')
->findAll();
$list_comments = $em->getRepository('AmBlogBundle:Comment')
->findBy(array('article_id'=>$article->getId()));
//In order to delete an article, we have to remove each object linked to an Article
foreach($list_tags as $value){
$article->removeTags($value);
}
foreach($list_comments as $value){
//We delete all the comments of an article
$em = $this->getDoctrine()->getManager();
$em->remove($value);
$em->flush();
}
// We remove the Article
$em = $this->getDoctrine()->getManager();
$em->remove($article);
$em->flush();
return $this->render('AmBlogBundle:Blog:delArticle.html.twig');
}
其實,我想只得到評論綁在我的文章,去相同的具有標記:/
我不知道我究竟做錯了什麼?有些幫助將是不錯的:)
感謝
好了,但我也得到了鏈接到我的實體文章也將刪除綁在文章右邊的所有標籤實體標籤?沒關係我回答我自己= D謝謝 – hyptos