alzambo
alzambo

Reputation: 147

Yii 2 ActiveDataProvider query with ->all() gives "Call to a member function andFilterWhere() on array" error

I need to pass ActiveDataProvider object to view and I can't understand why this:

$query = Incarico::find();

$dataProvider = new ActiveDataProvider([
    'query' => $query,
]);

works, while this:

$query = Incarico::find()
    ->joinWith('allegatos')           
    ->all();

$dataProvider = new ActiveDataProvider([
    'query' => $query,
]);

gives me the following error:

Call to a member function andFilterWhere() on array

Upvotes: 2

Views: 6236

Answers (1)

arogachev
arogachev

Reputation: 33548

You should not apply all() to $query since ActiveDataProvider query property expects valid ActiveQuery instance while you are passing results of that query.

Upvotes: 5

Related Questions