【发布时间】:2018-09-28 21:42:58
【问题描述】:
我有两个实体:“OriginNews”和“FollowUpNews”。它们是一对多相关的,因此一个 OriginNews 可以有多个 FollowUpNews。
在我的 OriginNewsAdmin 中,我只想在 listview 中显示 OriginNews,而且还通过 FollowUpNews 排序(如果已连接)...所以我决定通过像这样更改 createQueryMethod 来操作我的 listView-data。
/**
* @param string $context
* @return ProxyQueryInterface
*/
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->leftJoin('o.followUpNews', 'fun')
->addSelect('COALESCE(fun.importDate, o.importDate) AS HIDDEN sortDate')
->addOrderBy('sortDate');
return $query;
}
这应该将 followUpNews 加入 originNews 并按 importdate 排序......当我运行它时,我会得到错误。
在渲染模板期间引发了异常 ("[Semantical Error] line 0, col 94 near 'sortDate ASC,': 错误: 'sortDate' 未定义。”)。
奏鸣曲管理员是在开玩笑吗?我在上面一行定义了 sortDate 字段……即使我删除了“HIDDEN”关键字……没有变化! 问题出在哪里?
我的目标是,始终将具有最新 FollowUpNews 的 OriginNews 放在首位……这可能以另一种方式实现吗?
谢谢
【问题讨论】:
标签: doctrine sonata-admin dql