我在Native Query Doctrine 2中对结果的自定义排序有问题。我在服务器上测试了这个SQL:
SELECT
c.id, c.is_verified, c.email, c.phone, i.id as identityId,
i.firstname, i.lastname, g.id as groupId, g.name as groupName,
r.id as roleId, r.name as roleName
FROM
UserCredential c
JOIN
UserIdentity i
ON
i.id = c.identity_id
JOIN
Role r
ON
r.id = c.role_id
LEFT JOIN
`Group` g
ON
g.id = c.group_id
ORDER BY
i.firstname ASC
LIMIT
10
OFFSET
0
一切正常,但是当我将其重写为自定义存储库中的Native Query时:
$query = $this->_em->createNativeQuery('
SELECT
c.id,
c.is_verified,
c.email,
c.phone,
i.id as identityId,
i.firstname,
i.lastname,
g.id as groupId,
g.name as groupName,
r.id as roleId,
r.name as roleName
FROM
UserCredential c
JOIN
UserIdentity i
ON
i.id = c.identity_id
JOIN
Role r
ON
r.id = c.role_id
LEFT JOIN
`Group` g
ON
g.id = c.group_id
ORDER BY
:orderBy
LIMIT
:lmt
OFFSET
:ofs
', $rsm);
$query->setParameter('orderBy', implode(', ', $orderBy));
$query->setParameter('lmt', $limit);
$query->setParameter('ofs', $offset);
$ orderBy是数组$ column => $订单类型。
但是,如果我按参数更改顺序,则始终以默认排序(c.id ASC)返回此查询的结果。
我已经对此进行了测试并生成了查询,但我不知道为什么默认情况下始终会对结果进行排序。 Doctrine 2是否忽略了ORDER BY?