我有一个sql查询:
SELECT users.username, count(follows.user_id)
FROM follows
INNER JOIN users ON follows.follow_user_id=users.id
GROUP BY follow_user_id;
在奏鸣曲管理中,我想用追随者的数量过滤我的数据。请求有效,但我不能在奏鸣曲管理中使用它。
我的职责是:
public function callbackFilterFollow($queryBuilder, $alias, $field, $value)
{
if (!$value) {
return;
}
//$queryBuilder->select('username')->addGroupBy('o.id');
return true;
}
我不知道如何使用查询生成器来转换我的SQL查询。
发布于 2017-03-12 12:09:31
您是否将查询表映射到实体?如果不是的话,请看一下oneToMany关系文档的教义。
一旦您完成了这样的操作,请记住使用对象字段,而不是像表字段名下面那样!!
$qb->select('u.username, COUNT(f.user_id) as cnt')
->from('UserBundle:Follows' , 'f') //this is your entity
->leftJoin('UserBundle:Users','u') //your users entity
->groupBy('f.follow_user_id')
->getQuery()
->getOneOrNullResult();
您的实体可能需要完整的路径。但是有两件事我不明白你在做什么。
https://stackoverflow.com/questions/22020110
复制