Why I must use object in doctrine relation?
For example I have two Entity - Category and Post. From jquery I receice in controller many ids:
$categories = array(3, 5, 2);
And if I want get object then I must first get objects:
$cat = array();
foreach ($categories as $category) {
$cat[] = $this->getDoctrine()
->getRepository('AppBundle:Category')
->find($category);
}
And only now I can find my Posts:
$repository = $this->getDoctrine()
->getRepository('AppBundle:Post');
$query = $repository->createQueryBuilder('p');
$query->andWhere('p.category IN (:cat)')
->setParameter('cat', $cat);
$posts = $query->getQuery()->getResult();
Why I can't use simply ids categories in second query? Why I must pass object to query with relation? Why query builder can't see category_id instead of category?
It charged the database and increases page load time.