我是 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/