用QueryBuilder(Symfony)中的FormBuilder过滤器

发布于 2025-02-05 23:24:25 字数 463 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2025-02-12 23:24:25

我不确定您想要什么,但是$ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文