Hi all,
For some reason my relation is not working. I have the following two tables:
ppl_details //table name
id
person_id //foreign key corresponding to people.id
test_type
score
people //table name
id
name
age
I would like to perform a relational query in my list action which lists all ppl_details in a way so I can get the name of a person from the people table (people.name).
In my ppl_details model I have the following relation:
return array(
'ppls'=>array(self::BELONGS_TO,'People','id'),
);
In my controller I have the following code:
public function actionList()
{
$criteria=new CDbCriteria;
$criteria->with = array('ppls');
$pages=new CPagination(Ppl_details::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$models=Ppl_details::model()->findAll($criteria);
$this->render('list',array(
'models'=>$models,
'pages'=>$pages,
));
}
and the above relation is not working. When I try to access some of the people table data via $model->name it is not returning any value. I am using foreach in the view to iterate $models.
Can someone help me understand what I’ve got wrong in my code. I am using Yii 1.1 RC and one reacord from ‘people’ table corresponds to one record from ppl_details.
Thanks!