Answer the question
In order to leave comments, you need to log in
Yii 1.1 alias support in cSort?
Tell me, is it possible to add alias support to the CSort class in Yii 1.1 latest version?
Example:
// Объявляем критерию
$crt = new CDbCriteria();
$crt->alias = 'communityPosts'; // Устанавливаем alias с которым будем работать
if ($filter) {
if ($community->isMember()) {
$crt->scopes = array('pending', 'declined' => array('operator' => 'OR'), 'activeUser');
} elseif ($community->isOwner()) {
$crt->scopes = 'pending';
}
} else {
$crt->scopes = 'approved';
}
$sort = new CSort('Post');
$sort->defaultOrder = 'id DESC';
// Мне нужно использовать alias критерии который я установил ранее, что бы не писать "$crt->alias . '.id DESC'"
$sort->attributes = array(
'declined' => array(
'desc' => 'status DESC, id DESC',
),
'popular' => array(
'asc' => 'status',
'desc' => 'status DESC',
),
);
$sort->applyOrder($crt);
// Получаем записи
$posts = $community->posts($crt);
// До
$criteria->order.=$order;
// После
$criteria->order.=$criteria->alias.'.'.$order;
$attribute=($criteria===null || $criteria->alias===null ? $this->getModel($this->modelClass)->getTableAlias(true) : $schema->quoteTableName($criteria->alias)).'.'.$schema->quoteColumnName($attribute);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question