Finaly, I have create a method in my categoryRepositor, like this:
public function findOneUserCategoryById($user_id, $board_id)
{
$query = $this->getEntityManager()
->createQuery('
SELECT c FROM WebsiteBundle:Category c
JOIN c.users u
WHERE u.id = :user_id AND c.id = :category_id'
)
->setParameters(array(
'user_id' => $user_id,
'category_id' => $category_id)
);
try {
return $query->getSingleResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return null;
}
}
That work's fine and I use this method like this:
$em = $this->getDoctrine();
$category = $em->getRepository("WebsiteBundle:Category")
->findOneUserCategoryById(1, 5);