There seems to be an over sight in Doctrine 2.1 where it isn\'t easy to return a subset collection for an association.
http://www.doctrine-project.org/docs/orm/2.1/
What i would do:
class Category
{
protected $id;
protected $articles; // PesistentCollection
public function getVisableArticles(IArticleRepository $articleRepository)
{
return $articleRepository->getVisibleByCategory($this);
}
}
interface IArticleRepository
{
function getVisibleByCategory(Category $category);
}
Your doctrine's repository would implement IArticleRepository and the class won't know anything about your data storage/doctrine.