【发布时间】:2017-07-12 14:31:50
【问题描述】:
我有以下疑问:
$query = $qb->select($qb->expr()->substring("p.website",1,5).'AS country)
->from("AppBundle\Entity\Image" ,"p")
->where("p.aktuellste = 1")
->andWhere($qb->expr()->in('country',':country'))
->setParameter(':country','de')
->orderBy('country','DESC')
->getQuery();
例如我想选择网站的substring(1,2) 为de 的所有行。但是country 是 WHERE 子句中 Doctrine 的未知列。抛出以下异常:
SQLSTATE[42S22]:未找到列:1054 中的未知列 'sclr_0' 'where子句
有趣的是,Doctrine 知道 ORDER BY 子句中的 country 列。
有人知道如何解决这个问题吗?
【问题讨论】:
-
不确定这是否有帮助,但在所有 where 表达式中使用前缀 p。并且 MySQL 知道 order 子句中的列“country”,因为“临时”表(在 select 执行之后)具有字段 country。 (如果理解有误,请指正!!)
-
嘿,谢谢,但我已经试过这个了。问题是,学说在我的“图像”类中需要“国家”字段。
标签: php symfony doctrine-orm doctrine