I have the following table structure.
tb_posts has the field author_id which relates to tb_author.id
in YII i have the following in my posts activeRecord
public function relations()
{
return array(
'authorRelation' => array(self::BELONGS_TO, 'authorRecord', 'author')
);
}
How i do a search of posts of an authors with name ‘foo’? I am trying the following with no success
$criteria=new CDbCriteria;
$criteria->with = array('authorRelation');
$criteria->together = true;
$criteria->compare( 'author.name', 'foo', true );
$posts=PostsRecord::model()->findAll($criteria);
Set table alias for your models at init.
Finally: