Two instances of CActiveDataProvider with same model finder instance interfere

Hi guys, have an issue with CActiveDataProvider. I have next piece of code:




$newRequestsDataProvider=new CActiveDataProvider(SellerVerificationRequest::model()->new());

$suspendedRequestsDataProvider=new CActiveDataProvider(SellerVerificationRequest::model()->suspended());


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

			'newRequestsDataProvider'=>$newRequestsDataProvider,

            'suspendedRequestsDataProvider'=>$suspendedRequestsDataProvider,

));



And I have a view where two times I use CGridView. Thing is that I have both tables similar. They have totally identical data.

I think that the issue is in my model finder instance. SellerVerificationRequest::model()->suspended() and this SellerVerificationRequest::model()->new() - returns same object… Is there any ideas how to solve this?

Other idea is that this happens because of lazy initialization. As actual fetch executes after both CActiveDataProvider are set up.

Hm, how do your scopes on SellerVerificationRequest look like?

read this thread: http://www.yiiframework.com/forum/index.php/topic/29090-multiple-calls-of-activerecordmodel-with-criteria/page__view__findpost__p__140004

the problem is because youre are using pipeline scope functions not properly. You have to create separate CDbCriteria objects for each dataprovider and call applyScopes to apply scope criteria to those objects. then everything should work fine.





    /**

 	* @return array

 	*/

    public function scopes()

    {

        return array(

            'new'=>array(

                'condition'=>'status=1',

                'order' => 'requested_on DESC'

            ),

            'suspended'=>array(

                'condition'=>'status=4',

            ),

        );

    }



This has same issue as my previous code





$newRequestsDataProvider=new CActiveDataProvider('SellerVerificationRequest', array(

            'criteria' => array(

                'scopes' => array('new'),

            ),

        ));


        $suspendedRequestsDataProvider=new CActiveDataProvider('SellerVerificationRequest', array(

            'criteria' => array(

                'scopes' => array('suspended'),

            ),

        ));


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

			'newRequestsDataProvider'=>$newRequestsDataProvider,

            'suspendedRequestsDataProvider'=>$suspendedRequestsDataProvider,

		));



I’ve played a little with different combination and it seems that actually issue is the Criteria which is merged to one from two scopes as I have this in my logs:

SELECT * FROM seller_verification_request t WHERE (status=1) AND (status=4) ORDER BY requested_on DESC LIMIT 10