Answer the question
In order to leave comments, you need to log in
Yii2 query select not working?
$query = Products::find();
$query->select([
"NAME",
"ROUND(EXT_PRICE / EXT_RATIO, 2) AS EXT_PRICE_RATIO"
]);
$pagination = new Pagination([
'defaultPageSize' => 50,
'totalCount' => $query->count(),
]);
$result = $query->orderBy(['NAME'=>SORT_ASC])
->offset($pagination->offset)
->limit($pagination->limit)
->all();
var_dump($result);
array(9) {
[0]=>
object(app\models\Products)#101 (10) {
["_attributes":"yii\db\BaseActiveRecord":private]=>
array(1) {
["NAME"]=>
string(31) "Пылесос Philips"
}
...
Answer the question
In order to leave comments, you need to log in
The model will only have those fields that are in the table. Use asArray to get something else.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question