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(











here is the code of view:

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





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











)); ?>

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.


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



The immediate error is in


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.