Join Tables ? Proper Select

Hello,

I have 2 tables

1)StudentHasUser

2)Contract

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(

                    'criteria'=>array(

                        'condition'=>'user_userId='.$current_id,

                        '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 ?

Hi,

try this


            $criteria = new CDbCriteria;

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

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

            $criteria->addCondition("t.student_id='3'");

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

            print_r($resultSet);