I want to write SQL like this with Yii 2:
select id, 1 as type from user;
This is my code:
$query = User::find()->select(['id', '1 as type'])->all();
1
is a constant, not user's field
I want to add field type = 1
to the query result.
To disable quoting and escaping in certain part of the query, wrap it in yii\db\Expression:
use yii\db\Expression;
...
$query = User::find()->select(['id', new Expresssion('1 as type')])->all();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With