Perhaps I have not done this correctly so would appreciate some guidance. This is model JobApplication:
'job'=>array(self::BELONGS_TO, 'Job', 'job_id'),
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with=array('job');
$criteria->condition="x.user_id=:user_id";
$criteria->params=array(':user_id'=>Yii::app()->user->id);
$criteria->alias="x";
// these are all fields in the 'Job' model
$criteria->compare('title', $this->title, true);
$criteria->compare('location_id', $this->location_id, true);
$criteria->compare('expires_at', $this->expires_at, true);
$criteria->compare('active', $this->active, true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
CGridView attributes config:
array(
'name'=>'title',
'value'=>'$data->job->title',
),
array(
'name'=>'location_id',
'value'=>'$data->job->Location',
),
array(
'name'=>'active',
'value'=>'$data->job->IsActive',
),
array(
'name'=>'expires_at',
'value'=>'$data->job->ExpiresAtDate',
),
The attributes display correctly but the search function is throwing up an error. This is because those fields don’t belong to JobApplication model - but even if I do something like $this->job->title it still gives an error - Trying to get property of non-object.