用QueryBuilder(Symfony)中的FormBuilder过滤器
P是配置文件,u是用户。每个用户都有一个或多个配置文件。我想从拥有超过10点的每个用户中过滤一个配置文件。但是我只想保留每个符合条件的用户的一个配置文件。 在加入后,我需要为每个符合条件的用户占用一个值。
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->Join(User::class, 'u')
->Where('u.point > 10')
->andWhere('u.id = p.admin');
},
此代码“工作”,但它返回了所有配置文件,我只想为每个用户一个。
p is profile and u is user. Each user has one or more profiles. I want to filter one profile from each user who have more than 10 points. But I want to keep only one profile of each user that meets the condition.
I need that after the join only one value is taken for each user that meets the condition.
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->Join(User::class, 'u')
->Where('u.point > 10')
->andWhere('u.id = p.admin');
},
This code "works" but it returns all the profiles and I only want one for each user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您想要什么,但是$ query-> getingleresult()仅返回一个结果。
如果要选择一个特定的配置文件,则必须在所需条件下添加另一个配置文件。
I'm not sure what you want but $query->getSingleResult() returns only one result.
If you want to choose a specific profile you have to add another where with the condition needed.