search HAS_MANY relation

I have the following tables:

user (id, cv_personal_data_id),

cv_personal_data (id, firstname, surname, gender, address, ...),

cv_laboral_exp (id, user_id, position, seniority,... ),

cv_study (id, user_id, name, institution, average, ...),

cv_language (id, user_id, language_name, writing_level, ...)

In my User model I have defined the following relations:

   public function relations()


    return array(

        'cvLaboralExps' => array(self::HAS_MANY, 'CvLaboralExp', 'user_id'),

        'cvLanguages' => array(self::HAS_MANY, 'CvLanguage', 'user_id'),

        'cvStudies' => array(self::HAS_MANY, 'CvStudy', 'user_id'),

        'cvPersonalData' => array(self::BELONGS_TO, 'CvPersonalData', 'cv_personal_data_id'),


The problem is: logged in as a Company, I need to display a CGridView listing all the users and being able to search by any of the fields of the related tables, such as ‘position’ (from cv_laboral_exp), ‘language_name’ (from cv_languages), and so on. I can’t seem to find a solution to search fields that come from a HAS_MANY relation. I tried adding in the search() method of the User class the ‘with’ statement to the $criteria, in an attempt to search the position of a user laboral experience, but without success:


                $criteria->with = array('cvLaboralExps'=>array('select'=>'cvLaboralExps.position','together'=>true));

As you see there are a lot of relationships that form the CV of a user. I’d be very grateful if anyone could help me solve this, even if it implies changing the database/model structure.

See Searching and sorting by related model in CGridView in Yii’s wiki.

Thank you! I could solve it =)