CActiveDataProvider with a relation

Subcategory Model:


'active_category_products'=>array(self::HAS_MANY, 'Category_Product', 'subcat_id', 'with'=>'product', 'condition'=>'active=1', 'order'=>'prod_name'),

SubcategoryController:




public function actionView()

{

	$subcategory=$this->loadModel();

	

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

		'data'=>$subcategory->active_category_products,

		

		'pagination'=>array(

			'pageSize'=>5,

		),

	));

	

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

		'model'=>$subcategory,

		'dataProvider'=>$dataProvider,

	));

}



As you can see I use the ‘data’ property to reference the relation; however the pagination does not work with this and also it does not give the correct item count in CListView.

Anyone able to advise? Thanks.

I don’t understand very well the problem.

I can just advice you to use CLogRouter for log the ‘trace’ level of log in your webpage. So you can see the queries that are done.

Is a good system for debug, you can at least understand what the AR is fetching. Pay attention because sometime CActiveRecord->count() retrives wrong results, so is better to check the query. If the count is mistaken even the pagination work strange.

You can paste both here (the count query and the select too) and we can discuss what is going on.

Basically I want to be able to reference the ‘active_category_products’ relation in my controller. At the moment the only way I can do that is by using the ‘data’ property, however the pagination does not work with this and also it does not give the correct item count in CListView.

The other option I have, of course, is to repeat the relation in my controller using the ‘criteria’ property; but I would rather re-use the relation.

So is anyone able to advise?

did you find a solution foor this problem?

I also need the answear.

thx

I would like to do this also, so I can re-use my relations with CActiveDataProvider… any new developments?

Thanks!

I was having the same problem, this really helps