0

Как написать на ActiveRecord запрос такого вида select id, field1 + field2 + field3 AS sum from table where id = '1' ?

1 ответ 1

1

Посмотрите пример в документации:

class Room extends \yii\db\ActiveRecord
{
    public $volume;

    // ...
}

$rooms = Room::find()
    ->select([
        '{{room}}.*', // select all columns
        '([[length]] * [[width]] * [[height]]) AS volume', // calculate a volume
    ])
    ->orderBy('volume DESC') // apply sort
    ->all();

foreach ($rooms as $room) {
    echo $room->volume; // contains value calculated by SQL
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.