CActiveDataProvider and with()


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(



        'order'=>'create_time DESC',







// $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