Different items count for CArrayDataProvider and CActiveDataProvider

I have the following scenario:

My model "User" has a MANY_MANY relation named "friends" (related models are also "User" models)

So:


$friendsArrDataProvider = new CArrayDataProvider($model->friends);

$items_no1 = count($friendsArrDataProvider->getData()); //here 11;


$friendsActiveDataProvider = new CActiveDataProvider("User", array(

	'data' => $model->friends,

));


$items_no2 = count($friendsActiveDataProvider->getData()); //here 212 ?!?!?

I expected $items_no2 and $items_no1 to have the same value but it seems that CActiveDataProvider attribute totalItemCount is not updated related to the given data (I`m wrong?)

Any explanation will be great!

Hi.

I think your problem is you fill the CActiveDataProvider with "data" property.

You must fill it with ‘criteria’ property.

"data" property is the data that you want to retrieve, then It makes no sense you pass it directly.

I guess It is collecting data for each friend.

Well, it’s my opinion.

Regards.