【发布时间】:2019-07-30 09:52:20
【问题描述】:
我正在开发一个 symfony 项目,其后端是在学说和 api 平台框架中开发的。我需要获取一些详细信息以及检查另一个表中的字段,这将是一个状态。我们使用此状态在前端处理某些事情。
我试过了:-
$qb = $this->createQueryBuilder('contact');
$qb2=$qb;
$sub_query = $qb2->select('field')
->from('OtherTable','g')
->where("'id= '".$personId."'")
->OrderBy('updated_at', 'DESC')
->setMaxResults(1)
->getQuery()
->getResult();
$qb->select("contact.id,
contact.title,
count (distinct person.id) as
number_of_contacts_with_email',(".$sub_query.") as status")
->leftjoin('contact.people', 'person')
->leftJoin('person.jobs', 'jobs')
->groupBy('contact.id, contact.title');
$query=$qb->getQuery();
$result = $qb->getQuery()->getArrayResult();
return $result;
执行查询时出现此错误。
[Semantical Error] line 0, col 59 near 'OtherTable g': Error: Class 'OtherTable' is not defined.
这里怎么写这个子查询?有解决办法吗?
【问题讨论】:
-
仍未解决,出现错误!类未定义!
-
OtherTable实体表存在吗? -
Othertable 实体存在,但实体未在我的查询中正确执行,我已经在存储库中包含 $injected 实体。
-
如何在nativequery中编写整个查询,nativequery不适合我!
标签: php symfony doctrine-orm doctrine api-platform.com