[SOLVED] CActiveDataProvider with CDbCriteria problem

I have a model called ActionCategories that ‘HAS_MANY’ Actions. The relation is defined as ‘actionsRel’. I have the following in my controller:




$criteria = new CDbCriteria();

$criteria->together = TRUE;

$criteria->with = 'actionsRel';

$criteria->condition = 'actionsRel.task_status = \'NOT DONE\'';


$dataProvider = new CActiveDataProvider(ActionCategory::model(), array('criteria'=>$criteria));

$this->render('index', array('actionCategories' => $dataProvider));



When I use this the CListView widget I’m using in my view only returns 4 records. Also, if I tail the MySQL logs I notice that lazy loading is being performed.

Is there any way to implement the above with eager loading?

I found a way to achieve this (took me days) and am posting it here in case anyone else encounters the same problem (and for discussion):




$criteria = new CDbCriteria();

$criteria->with = 'actionsRel.actionAssignedToRel';

$criteria->condition = 'actionsRel.task_status = \'NOT DONE\'';


$model = ActionCategory::model()->findAll($criteria);

$dataProvider = new CArrayDataProvider($model);

$this->render('index', array('actionCategories' => $dataProvider));



I’m not convinced that this is an ideal solution, but it works. Eager loading is utilised instead of lazy loading (which was my goal).