rabib
(Rabib Sust)
February 24, 2015, 12:53pm
1
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.
phtamas
(Phtamas)
February 24, 2015, 3:28pm
2
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.
Pasman
(Pasman P)
February 24, 2015, 7:53pm
3
rabib:
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.
Try this:
$queryValue = Mymodel::find()->where(['>', 'sorting_value', $sort1])->min('sorting_value');