gpt4 book ai didi

php - 在 Symfony 2 中加入查询

转载 作者:行者123 更新时间:2023-11-28 23:30:15 25 4
gpt4 key购买 nike

我是 Symfony 的新手,我有 2 个实体(不是我创建的):

  • 第一个实体:test1 (id,test2_id)
  • 第二个实体:test2 (id,label)

我想创建从 test where test2.label = 1 中选择的查询。

$Websites = $this->_em
->createQuery("
SELECT w
FROM \Bundle\Entity\test1 t1
JOIN t1.test2 t2
WHERE t2.label=1")
->getResult();

但是我得到一个错误:

Bundle\Entity\test1 has no association named test2

是否有解决方案或其他方法使其工作。

最佳答案

试试这个:

$Websites = $this->_em
->createQuery("
SELECT w
FROM \Bundle\Entity\test1 t1
JOIN \Bundle\Entity\test2 t2
WHERE t2.id = t1.test2_id AND t2.label=1")
->getResult();

你也可以使用createQueryBuilder方法

关于php - 在 Symfony 2 中加入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37569586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com