Invalid Yii2 backtrack in request

If I run this,

->addSelect(new Expression('IFNULL(SUM(supply), 0) AS sum_supply'))

      

it generates

IFNULL(SUM(supply), `0` AS `sum_supply` FROM ...

      

which is an invalid request, backstep around 0.

How do I delete this answer?

+3


source to share


1 answer


Quick fix:

->addSelect([new Expression('IFNULL(SUM(supply), 0) AS sum_supply')])

      

or



->addSelect(['IFNULL(SUM(supply), 0) AS sum_supply'])

      

An array should be used in this case because it addSelect()

separates the input string with a comma

+5


source







All Articles