I have a model in which I have the following relation defined:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
...
'milestone_category' => array(self::BELONGS_TO, 'MilestoneCategory', 'MilestoneCategoryID'),
);
}
and the search function of the same model is as follows:
public function search($id=NULL)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$conditions=array();
$params1=array();
$params2=array();
if (isset($id)) {
$conditions[]='ApplicantID=:ApplicantID';
$params1=array('ApplicantID'=>$id);
}
if (isset($_GET['dropDownStatus'])) {
$criteria->with = 'milestone_category';
$conditions[]='milestone_category.StatusID=:StatusID';
$params2=array('StatusID'=>$_GET['dropDownStatus']);
}
$criteria->condition=implode(' AND ', $conditions);
$criteria->params=array_merge($params1, $params2);
...
When viewing the result of this search for the first time, at which point the $_GET variable has not been set, then all rows are returned, ie, the second condition where I filter with the relation ‘milestone_category’ has not been applied.
Then, when I call this function with the $_GET variable defined, I get the expected data set.
The problem is that, once I have called this function with the $_GET variable set, then if I call this function again with the $_GET variable not set, it is not returning the full data set anymore, as if the relation ‘milestone_category’ is still active…
Is there a way of ‘unsetting’ this relation, or condition ? To be honest, I am not sure what is the problem, and where to start looking…