In my project, i am using a cgridview to show records corresponding to the user. name the model i am using is SupplierResponseMaster. this model have a relation to another model
named AccountsCorporate and the relation is 'corporate' => array(self::BELONGS_TO, 'AccountsCorporate', 'corporate_id'),. the search function is
public function search()
{
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id, true);
$criteria->compare('survey_id', $this->survey_id, true);
$criteria->compare('corporate_id', $this->corporate_id, true);
$criteria->compare('user_id', $this->user_id, true);
$criteria->compare('status', $this->status, true);
$criteria->compare('common_notes', $this->common_notes, true);
$criteria->compare('system_rank', $this->system_rank, true);
$criteria->compare('request_coordinator_rank', $this->request_coordinator_rank, true);
$criteria->compare('is_short_listed', $this->is_short_listed);
$criteria->compare('short_listed_date', $this->short_listed_date, true);
$criteria->compare('is_awarded', $this->is_awarded);
$criteria->compare('awarded_date', $this->awarded_date, true);
$criteria->compare('created_by', $this->created_by, true);
$criteria->compare('created_date', $this->created_date, true);
$criteria->compare('modified_by', $this->modified_by, true);
$criteria->compare('modified_date', $this->modified_date, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
in my grid view, i need to load the details from the model using the search(or any alternative method) function for the given user_id and also get the corporate name from the AccountCorporate model using the corporate_id. please help me to find a solution for this.
thanks in advance.
Create new relation
userwith'user' => array(self::BELONGS_TO, 'Users', 'user_id'),then to get the details of user for grid you can use
$data->user->nameFor corporate name use
$data->corporate->name