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

Hi All,

I am modifying this query to yii2 active record.


$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 "Call to a member function where() on a non-object" error.

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

Please help!

Thanks in advance.

Why?

Active Record is not an universal replacement for SQL. Using it to fetch a single scalar value from database seems to be overcomplicating things. Just execute a simple plain SQL query.

Try this:


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