是否可以在实体上调用存储库方法?我的意思是这样的
$article = $em->getRepository('Entities\Articles')->findOneBy(array('id' => $articleId));
$category = $em->getRepository('Entities\Categories')->findOneBy(array('id' => 86));
$article->addArticleToCategory($category);
其中 addArticleToCategory 是存储库中的方法(只是示例代码)
public function addArticleToCategory($category){
$categoryArticles = new CategoryArticles();
$categoryArticles->setArticle(!!/** This is where I want to have my variable $article from this method call **/!!);
$categoryArticles->setCategory($category);
$this->getEntityManager()->persist($categoryArticles);
$this->getEntityManager()->flush();
}
最好的方法是什么?
另外我想知道将自定义设置/创建方法放在存储库中是一种好习惯吗?