Collecting Data From Related Models

Hai everyone,

I am searching for an example to get related data from more than one model.

This is my scenario, help me with that.

I have a model named Traveler with two attributes

TID - Traveler ID and

ProfileID - that belongs_to profile model.

Now i need to get the profile information for the particular Traveler say for example TID=2;

Where i have to use this condition and how can we use with() method for achieving this?

Thanks in advance.

kind Regards,



please see

Also i will put the exmaple like

1) model.php

   public function relations() {

        return array(

            'users' => array(self::BELONGS_TO, 'users', 'user_id'),



2) admin.php







3) Then after filer search code

=>put your code in serch function

   if(isset($this->user_id) && !empty($this->user_id)){

            $criteria = new CDbCriteria;

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

            $criteria->join = ' LEFT JOIN `users` AS `tu` ON t.user_id =';



Thanks for the reply,

I got the datas from related models using the below sample code.

/* Sample Code 		

$criteria = new CDbCriteria;

$criteria->with = array('foreign_table1',



$criteria->together = true; // ADDED THIS

$criteria->select = array('id');

$criteria->condition = "foreign_table1.col1=:col_val AND 


$criteria->params = array(':col_val' => some_val, ':col_val2' => other_val);

$criteria->order = 'foreign_table3.col5 DESC';

$criteria->limit = 10;


$result = Model_Name::model()->findAll($criteria);

and referred these links

Fetching Data from Related Models

Understanding about Relationships in models