yiisoft/yii — Issue #468: CMssqlCommandBuilder::checkCriteria fails to account for a table alias in complex queries
Author: ljurgs
Created: 2012-03-07 12:35:42+00:00
State: open

When doing complex queries using CActiveDataProvider and CDbCriteria with pagination but without a set order (ala CGridView) CMssqlCommandBuilder::checkCriteria() fails to account for the need to apply a table alias when it creates a default order.

The following fix works for me:

Changed the line
$criteria->order = is_array($table->primaryKey)?implode(',',$table->primaryKey):$table->primaryKey;

to:

$order = is_array($table->primaryKey)?implode(',',$table->primaryKey):$table->primaryKey;
if ('' !== $criteria->alias) {
$criteria->order = $criteria->alias . '.' . $order;
} else {
$criteria->order = $order;
}

I'm sorry my bug report is not more complete but any query with multiple join with matching column names should create the condition if paging is applied without an order.