Y
Y
Yuriy2019-01-25 14:43:26
Yii
Yuriy, 2019-01-25 14:43:26

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);

and EXT_PRICE_RATIO is not in the output ... the fields are only those in the table.
Tried through addSelect, the same result, what's wrong?
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

1 answer(s)
A
Alexander Izmailov, 2019-01-25
@yous

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 question

Ask a Question

731 491 924 answers to any question