https://stackoverflow.com/questions/34640661/doctrine-query-one-to-many-unidirectional-with-join-table-association-from-in
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('SomeBundle:Post', 'p')
->join('p.categories', 'c')
->where('c.id = :categoryId')
->setParameter('categoryId', $categoryId)->getQuery()->getResult();
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('SomeBundle:Post', 'p')
->join('p.categories', 'c')
->where($qb->expr()->in('c.id', ':categoryIds'))
->setParameter('categoryIds', $categoryIds) // array of ids
->getQuery()->getResult();
//===============================================================================
$tag = $tag->getId();
$conn = $this->get('database_connection');
$res = $conn->prepare('
SELECT p.id,p.title,p.slug,p.shortcontent,p.published_at
FROM post p, blog_post_tag chuj
where p.id=chuj.post_id
AND chuj.tag_id=:tag
ORDER BY p.published_at DESC');
$res->bindParam(':tag', $tag, PDO::PARAM_INT);
$res->execute();
dump($res->fetchAll(PDO::FETCH_ASSOC));
$query = $this->getDoctrine()->getManager()
->createQuery('SELECT p,t FROM App:Post p left JOIN p.tags t ORDER BY p.publishedAt DESC');
Te same zapytnia:
return $this->getEntityManager()
->createQuery(
'SELECT o FROM EnpOrderBundle:Order o INNER JOIN o.relatedOrders orr WHERE orr.id IN (SELECT o22.id FROM EnpOrderBundle:Order o22 WHERE o22.uniqueHash = :uniqueHash)'
)
->setParameter('uniqueHash', $orderUniqueHash, PDO::PARAM_STR)
->getResult();
return $this->getEntityManager()->createQueryBuilder()
->select('o')
->from(Order::class, 'o')
->leftJoin('o.relatedOrders', 'ro')
->where('o.id IN (SELECT ooooo.id FROM EnpOrderBundle:Order ooooo WHERE ooooo.uniqueHash = :uniqueHash)')
->where('ro.id IN (SELECT os.id FROM EnpOrderBundle:Order os WHERE os.uniqueHash = :uniqueHash)')
->setParameter('uniqueHash', $orderUniqueHash, PDO::PARAM_STR)
->getQuery()
->getResult();