ActiveDataProvider not working with a "where"

hello,

I’m blocking on a problem and would like to have your advises:

I try to display a grid for each user only with its own Orders.

When I do the following everything work fine:




        $dataProvider = new ActiveDataProvider([

                'query' => OrderOperation::find(),

                

                'pagination' => [

                    'pageSize' => 5,

                ],

            ])



But when I’m trying to prefilter the dataprovider with only the orders of the users, it’s not working and get the following error : The “query” property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.




        $dataProvider = new ActiveDataProvider([

                'query' => orderOperation::find()

                    ->where(['user_id' => $userID])

                    ->orderBy('id')

                    ->all(),

                

                'pagination' => [

                    'pageSize' => 5,

                ],

            ])



What Am I doing wrong ?

Thx

query params of ActiveDataProvider config is an ActiveQuery, instead you are passing items array.

You have to change




orderOperation::find()

                    ->where(['user_id' => $userID])

                    ->orderBy('id')

                    ->all(),



in




orderOperation::find()

                    ->where(['user_id' => $userID])

                    ->orderBy('id')



So your $dataProvider becomes:




        $dataProvider = new ActiveDataProvider([

                'query' => orderOperation::find()

                    ->where(['user_id' => $userID])

                    ->orderBy('id'),


                

                'pagination' => [

                    'pageSize' => 5,

                ],

            ])



Thanks a lot Fabrizio, you save my day :)