$qb = $this->createQueryBuilder('t');
return $qb
->join('t.customers', 'c')
->where($qb->expr()->eq('t.user', $user->getId()))
->andWhere($qb->expr()->gt($qb->expr()->count('c'), 0))
->orderBy('t.name')->getQuery()->getResult();
上面的查询使用GROUP(Doctrine2产生的一个)是给我这个错误:获得“#1111 - 无效使用组功能的”没有在MySQL
#1111 - Invalid use of group function
,但奇怪的是我” m不使用GROUP BY
。任何帮助非常感谢,谢谢。
SELECT t0_.id AS id0,
t0_.slug AS slug1,
t0_.name AS name2,
t0_.description AS description3,
t0_.user_id AS user_id4
FROM tag t0_
INNER JOIN customers_tags c2_ ON t0_.id = c2_.tag_id
INNER JOIN customer c1_ ON c1_.id = c2_.customer_id
WHERE t0_.user_id = 1 AND COUNT(c1_.id) > 0
ORDER BY t0_.name ASC
先生,你让我一天都行。自24小时以来一直苦苦挣扎,对数组集合(数组集合中的指定项目或数组集合的大小为0)进行双重检查,这种方法完美无缺。 – YumeYume 2017-01-13 08:46:04
这应该是被接受的答案:) – 2018-01-25 20:29:17