是否可以在實體上調用存儲庫方法? 我的意思是這樣來自實體的調用存儲庫方法
$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();
}
什麼是做到這一點的最好方法是什麼?
另外我想知道是否將自定義設置/創建方法放入存儲庫是一種很好的做法?
那麼,甚至用於存儲設置/添加方法的存儲庫?或者他們僅適用於獲取方法? –