I can’t seem to get a left join working. I think the problem is in the relations, but I don’t quite understand it. The actual sql is as follows:
SELECT rantId, mp3, description FROM Topic left join Rant on Rant.topicId = Topic.topicId where Topic.licenseeId = 0 order by createDate desc
In my controller I have:
$criteria=new CDbCriteria(array(
'with'=>array('rants'),
'together'=>true,
'join' => 'LEFT JOIN Rant on t.topicId = Rant.topicId where t.licenseeId = '.$session["licenseeId"],
'order'=>'createDate desc',
));
$dataProvider=new CActiveDataProvider('Topic', array(
'pagination'=>array(
'pageSize'=>20,
),
'criteria'=>$criteria,
));
In my ‘Topic’ model I have the following:
public function relations()
{
return array(
'rants' => array(self::BELONGS_TO, 'Rant', 'topicId'),
'rant' => array(self::HAS_MANY, 'Rant', 'topicId'),
'rantCount' => array(self::STAT, 'Rant', 'topicId'),
);
}
My view references the data as follows:
$data->rant->rantId
Can anyone point me in the right direction?