对象排序顺序错误

时间:2014-03-25 00:51:34

标签: php modx-revolution xpdo

我试图弄清楚xPDO SQL查询的排序顺序有什么问题,

此查询

$criteria = $this->modx->newQuery($table);
$criteria->sortby($sortby,$sortdir);
$options = $this->modx->getCollectionGraph($table,$criteria);
$criteria->prepare();
echo '<pre>'.$criteria->toSQL().'</pre>';

导致这个SQL~正确无误:

SELECT `Location`.`id` AS `Location_id`, `Location`.`created` AS `Location_created`,
 `Location`.`modified` AS `Location_modified`, `Location`.`location` AS 
`Location_location`, `Location`.`group` AS `Location_group`, `Location`.`comment` 
AS `Location_comment` 
FROM `flow_location` AS `Location` ORDER BY location asc

但是,如果我尝试循环查询:

foreach($options as $option) {
    echo $option->get($value).'<br>';
}

它将按数据库中的订单ID显示记录!?

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您按location asc排序,但查询中未定义location。您将列location重命名为Location_location,因此您应按Location_location asc排序。

SELECT `Location`.`id` AS `Location_id`, `Location`.`created` AS `Location_created`,
 `Location`.`modified` AS `Location_modified`, `Location`.`location` AS 
`Location_location`, `Location`.`group` AS `Location_group`, `Location`.`comment` 
AS `Location_comment` 
FROM `flow_location` AS `Location` ORDER BY location asc