How to create criteria with joining in yii

I have tables, one - profileand the other - rating. ratinghas a field profileidthat is the primary key for profile.idand a field with rating values. Now I want to find the field with the highest rating and display the corresponding profile. Since I'm new to the YII framework, I am having problems with this. Please help me get out of it. What I am doing is described below.

$topRage=new CDbCriteria();
$topRage->select="*";
$topRage->alias="t1";
$topRage->order="rateing DESC";
$topRage->join="JOIN `ratings` ON `profile`.`id` = `t1`.`profileId`";
$topRage->limit="1";
+3
source share
2 answers

Try the following:

join='JOIN profile ON profile.id = t1.profileId';

If you do this: Ratings::model()->findAll($topRage)then the grading table is already requested, so you need to join the profiling table.

Edit:

for echo you will need to do this:

$echo "Rating id: ".$rating->id."|&nbspProfile Id: ".$rating->profile->id."|&nbspProfile Name: ".$rating->profile->name."|&nbspRating: ".$rating->ratingvalue;

$rating .

find($topRage) findAll($topRage) limit, .

+1

.

$topRage=new CDbCriteria();
$topRage->select="*";
$topRage->alias="t1";
$topRage->order="rateing DESC";
$topRage->limit="1";

$rating=Ratings::model()->findAll($topRage);
$profile=Profile::model()->findByPk($rating->profileId);
+1

All Articles