Join Tables ? Proper Select


I have 2 tables



In my first table I have student_id, user_id columns,

In Contract table I have contract_id and student_id as foreign key.

Now in contract/index I want to display only that student_id for users that are related in studentHasUser table.

for example in my StudentHasUser table I only show students for user that is logged:

$current_id = Yii::app()->user->getId();

                    $dataProvider=new CActiveDataProvider('StudentHasUser', array(



                        'order'=>student_studentId DESC', )


Now how I can restrict display contract for users that are in same column with students. How should I select it ?


try this

            $criteria = new CDbCriteria;

            $criteria->select = 't.*, tu.* ';

            $criteria->join = 'JOIN users as tu on = t.user_id';


            $resultSet    =    StudentHasUser::model()->findAll($criteria);