CActiveDataProvider and with()

Hello!

I want to load relational tables with CActiveDataProvider.

When I go to documentation of CActiveDataProvider, I see the following snippet of code:




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

    'criteria'=>array(

        'condition'=>'status=1',

        'order'=>'create_time DESC',

        'with'=>array('author'),

    ),

    'pagination'=>array(

        'pageSize'=>20,

    ),

));

// $dataProvider->getData() will return a list of Post objects



So ‘with’=>array(‘author’), is specified for criteria. When I try to do pretty much the same in my application, and then trying to read property of related table I get error at line <?=$item->source->name?>:

Can someone explain is it possible at all to use with() method in CActiveDataprovider and what am I doing wrong?

Forget it, that was my bad, related table was empty )

Possible that your source is NULL? The message you received indicates that it failed to find a result for the source item, and you’re not checking it is not null before accessing the name property.

The syntax is correct, so I think the problem has to be data integrity or the actual relationship definitions.

You are absolutely right!

I understood it just a couple a minutes ago.

Thanks for fast reply