Answer the question
In order to leave comments, you need to log in
CDbCriteria and sorting?
Good day!
There are three tables - articles, translations and comments.
Links:
Article Model
public function relations() {
return array(
'translations' => array(self::HAS_MANY, 'ArticleTranslation', 'articleId'),
'comments' => array(self::HAS_MANY, 'Comment', 'objectId'),
);
}
public function relations() {
return array(
'article' => array(self::BELONGS_TO, 'Article', 'objectId'),
);
}
public function relations() {
return array(
'article' => array(self::BELONGS_TO, 'Article', 'articleId'),
);
}
$criteria = new CDbCriteria();
$criteria->addCondition('t.Category > 0');
$criteria->limit = 3;
$criteria->with = array(
'comments' => array(
'select' => array(
'commentText',
'likes'
)
),
'translations' => array(
'select' => 'title'
)
);
$articleTranslations = Article::model()->findAll($criteria);
$data['comments'] = $articleTranslations;
$criteria->order = 'comments.likes DESC'
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