Category: dql

JOIN DQL SYMFONY

i want to count how many baby for a parent class abonnementRepository extends DoctrineORMEntityRepository { public function SumEnfantDQL($id) { $entityManager = $this->getEntityManager(); $query = $entityManager->createQueryBuilder(); $query->select(‘sum(o.id) AS somme’); $query->from(‘AppBundle:enfant’, ‘o’); $query->join(‘AppBundle:User’,’p’)->where(‘p.id = :id’); $rez = $query->getQuery()->getResult(); return $rez; } }…

Doctrine: retrieving an ordered single entity from a one to many relationship

Suppose the following structure database structure – whereby a category has many articles, and an article has many comments: Category: – id Article: – id – category_id Comment: – id – created_at – article_id Using Doctrine, what is the best/standard…

Symfony get unread messages and group them user

I want to retrieve the number of unread messages, and group by user It returns an array with the number of unread messages but I can’t group by user. Symfony 4 Controller: $query = $this->repository->unreadCount() ->setParameter(“user”, $user) ->groupBy(“u.sender”) ->select(‘count(u.id)’) ->getQuery();…

MEMBER OF with array_values AND operator

there is my problem : return $this->createQueryBuilder(‘p’) ->select(‘p as post’) ->where(‘:tags MEMBER OF p.tags’) ->setParameter(‘tags’, array_values($tagArray)) ->orderBy(‘p.postedAt’, ‘DESC’) ->setFirstResult($start) ->setMaxResults($limit) ->getQuery() ->getResult() ; With this code, I can retrieve all posts that have as tags those present in $tagArray. But…