Cdbcriteria

I’ve got 3 tables.

1-students

2-courses

3-student_courses with both primary keys.

I also have a cgridview with students.

I would like to filter the cgridview to show all students that are nor enrolled in any course.

I can acomplish this by setting a method in model like this:




  public function alunos_sem_curso() {

     

     $where="id not in (select aluno from app_alunos_cursos)";

     

     $count=Yii::app()->db->createCommand("SELECT COUNT(*) FROM app_alunos where ".$where)->queryScalar();

     $sql="select * from app_alunos where ".$where;


     $dataProvider=new CSqlDataProvider($sql, array(

         'totalItemCount'=>$count,

         'pagination'=>array(

         'pageSize'=>100,

    ),

    ));

    return $dataProvider;

 }



and then I render this in a separate view.

it works ok, but I can´t have filters and sort in cgridview with this approach.

I would like to do the same using CDbCriteria and CActiveDataProvider so I could use the same cgridview to do everything.

Is this possible? Anyone knows how to do it?

probably using "with" somehow…

Thanks in advance

Take a look at this.

Oh by the way all I did was google ‘yii cgridview relation sort’ and found it as the first item.