Yii Framework Forum: Join Tables ? Proper Select - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Join Tables ? Proper Select Rate Topic: -----

#1 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 25 August 2013 - 03:32 PM

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', )
                ));

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

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 905
  • Joined: 19-February 13
  • Location:India

Posted 25 August 2013 - 11:34 PM

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);

Thanks,
Ankit Modi
Skype : amodi06
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users