Filtering for Relational Model Fields

Dear Yii Users,

I am having difficulty getting the filtering to work in CGridView for relational fields from another model.

URL Reference: Yii 1.1: Searching and sorting by related model in CGridView

I follow the codes and it seems to be returning me the inputs from the other model. Everything looks fine but unfortunately, the filter is not working.

On Search, it will display a quick load icon but failed to filter accordingly. Upon checking further, I noticed the input is wrong. I am using Google Inspect Element and noticed the following:

<input name="User[full_name]" type="text">

I am using User model, relational to Biodata. Shouldn’t it be Biodata[full_name]? If this is, where should I be looking at the codes?

Thank you. :D

You need to define the custom search function. I don’t think Yii can do this for you. Example form my code (a bit different), we have defined the age groups and every person has birthday. The search function in User model has added this code:

//find by age group


  $group = AgeGroup::model()->findByPk($this->_ageGroup);

  $minBirthday = date('Y-m-d', strtotime('-'.$group->max_age.' year', time()));

  $maxBirthday = date('Y-m-d', strtotime('-'.$group->min_age.' year', time()));

  $criteria->compare('birthday', '>='.$minBirthday);

  $criteria->compare('birthday', '<='.$maxBirthday);


all age Groups i display in a dropdown and _ageGroup is a field that is not persistant and contains the selected ageGroup.

Hope it helps.

Hello Renegat59,

Thank you for your suggestion. I will get back to you if I can solve with your method as I have moved on to other parts before getting back at this.

Much appreciated. ::)