原则 2 查询产品是否等于多个类别
$categories= array(3,20,24);
$qb = $this->em->createQueryBuilder();
$qb->select('p')
->from('\Entities\Productss', 'p')
->leftJoin('p.category', 'c')
->andWhere('p.id =?1')
->andWhere('p.id =?2')
->andWhere('p.id =?2')
->setParameter(1, $categories[0])
->setParameter(2, $categories[1])
->setParameter(3, $categories[2])
->getQuery();
这不允许多个位置...
$categories 是一个数组,其中包含必须匹配的类别才能选择正确的产品。例如鞋子(3),黑色(20),小号(24)
可以吗?
$categories= array(3,20,24);
$qb = $this->em->createQueryBuilder();
$qb->select('p')
->from('\Entities\Productss', 'p')
->leftJoin('p.category', 'c')
->andWhere('p.id =?1')
->andWhere('p.id =?2')
->andWhere('p.id =?2')
->setParameter(1, $categories[0])
->setParameter(2, $categories[1])
->setParameter(3, $categories[2])
->getQuery();
this doesnt allow multiple wheres...
$categories is an array which consist of categories it must match in order to select correct products. such as shoes(3), black(20), small(24)
possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Doctrine 的文档中,我发现了这一点:
It should be possible to put a subquery in this function。我自己从未使用过,但请尝试一下。
编辑
我知道这是一个多对多的关系。在这种情况下,您应该使用
MEMBER OF
选项。所以就像:
In the documentation of Doctrine I found this:
It should be possible to put a subquery in this function. I never used it myself, but give it a try.
EDIT
I understand it is a many-to-many relation. In this case you should use the
MEMBER OF
option.So like: