Rabib
Rabib

Reputation: 430

How to use where() condition with min() in ActiveQuery

I am modifying this query to Yii2 ActiveRecord.

$query = "SELECT min(sorting_value) as sorting_value FROM table WHERE sorting_value>'$variable'"

As far I have done this:

$queryValue = Mymodel::find()->min('sorting_value')->where(['sorting_value' > $sort1]);

And it is showing this error:

Call to a member function where() on a non-object

How can I solve this issue. I can't use where condition with min() function.

Upvotes: 1

Views: 5514

Answers (1)

soju
soju

Reputation: 25312

Since min() will not return ActiveQuery object, you should simply use where() before :

$queryValue = Mymodel::find()->where(['>', 'sorting_value', $sort1])->min('sorting_value');

Upvotes: 8

Related Questions