为什么这样做:
$query = $this->_em->createQuery(
'SELECT ua.id, ua.correct, (ua.user) as user_id
FROM AppBundle:UserAnswer ua
INDEX BY ua.id'
);
但是,当我尝试按相关实体用户编制索引时,它不再有效:
$query = $this->_em->createQuery(
'SELECT ua
FROM AppBundle:UserAnswer ua
INDEX BY ua.user'
);
收到错误:
[2/2] QueryException: [Semantical Error] line 0, col 83 near 'user': Error: Invalid PathExpression. Must be a StateFieldPathExpression. +
[1/2] QueryException: SELECT ua
FROM AppBundle:UserAnswer ua
INDEX BY ua.user +
更改为:
$query = $this->_em->createQuery(
'SELECT ua.id, ua.correct, (ua.user) as user_id
FROM AppBundle:UserAnswer ua
INDEX BY (ua.user)'
);
引发错误:
[2/2] QueryException: [Syntax Error] line 0, col 126: Error: Expected end of string, got '(' +
[1/2] QueryException: SELECT ua.id, ua.correct, (ua.user) as user_id
FROM AppBundle:UserAnswer ua
INDEX BY IDENTITY (ua.user) +
如何使用键作为外键索引结果数组?