I’m using SF2.1 with Doctrine2
I have 2 entities : Category and Article, linked with a oneToMany relation.
I want to retrieve all articles of a specific category, but only the published ones ….
I show you what I do for the moment :
// in /Entity/category.php :
public function getAllArticlesPublished(){
$articles = array();
foreach($this->getArticles() as $article){
if($article->isPublished()) $articles[] = $article;
}
return $articles;
}
Is this the good way to do it ? It doesn’t look good to parse the whole array of Articles … but I don’t want to do this in the repository becauseit concerns a specific Category.
Any hint for me ?
You might take a look at Filtering Collections. If it doesn’t solve your problem, then a repository would be the best place for stuff like this.