Join With Two Table

I want to get the data from two tables.I have used the below code to do so. I am new to YII, if i am using the wrong way,please suggest me the right way.

Here is the code of controller:

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


    'criteria'=>array(


        'with'=>'leave',


        'together'=>true,


        'condition'=>'leave.user_id=:user_id',


        'params'=>array(':user_id'=>$this->loadModel(Yii::app()->user->getId())->user_id),              


    ),


));


 $this->render('admin',array(


'dataProvider'=>$dataProvider,


));

here is the code of view:

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘id’=>‘users-grid’,

‘dataProvider’=>$dataProvider,

‘columns’=>array(

array(


'header' =&gt; 'Leave Type',


'name'=&gt;'leave_type',


'value'=&gt;'&#036;data-&gt;leave-&gt;leave_type',  


),      


'employee_code',


'username',


'password', 


array(


    'class'=&gt;'CButtonColumn',


),

),

)); ?>

My Problem is: I am joining two tables User and Leave. I want to get the data of users from Leave table as well as the users table. the above code shows me data from user table, when i try to show data from Leave table it throws me following Error:

Trying to get property of non-object

Please help me to get out of this problem.

UPDATE

here is my user model relations:

return array(

'leaves' =&gt; array(self::HAS_MANY, 'Leaves', 'leave_id'),


'creator' =&gt; array(self::BELONGS_TO, 'Users', 'created_by'),


'updator' =&gt; array(self::BELONGS_TO, 'Users', 'modified_by'),   


'leave' =&gt; array(self::HAS_MANY, 'Leaves', 'user_id'),  


);

Here is my leave model relations:

return array(

    'user' =&gt; array(self::BELONGS_TO, 'Users', 'user_id'),


    'creator' =&gt; array(self::BELONGS_TO, 'Users', 'created_by'),


    'updator' =&gt; array(self::BELONGS_TO, 'Users', 'modified_by'),           


);

Hi,

The immediate error is in




'value'=>'$data->leave->leave_type',



Because you have defined ‘leave’ as a HAS_MANY relation, $data->leave is not an Leave object but an array of it.

But, um, you may have error in the definition of ‘leave’ relation and the construction of the query criteria.

I’d like to know the table schema of User and Leave.

[solved]