• Как перевести SQL с помощью Yii2 ActiveRecord?

    K1R1LL
    @K1R1LL Автор вопроса
    php (native, Yii2, Laravel), javascript, sql
    Спасибо за ответ, Алексей.
    Запрос почему-то не сработал...
    Модели связал вот таким способом. Что-то неверно?

    class Slot extends \yii\db\ActiveRecord {
        public function getRoom() {
             return $this->hasOne(Room::className(), ['id' => 'room_id']);
        }
    }


    class Room extends \yii\db\ActiveRecord {
         public function getMeetings() {
               return $this->hasMany(Meeting::className(), ['room_id' => 'id']);
         }
    }


    В дебагере

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'room.title' in 'field list'
    The SQL being executed was: SELECT `slot`.logo as `dir`, `room`.title as `room`, `meeting`.logo as `logo`, `meeting`.title as `title`, `meeting`.start as `start`, `meeting`.end as `end` FROM `slot` WHERE slot.screen_id = 1 AND meeting.start < NOW() AND meeting.end > NOW()
    
    Error Info: Array
    (
        [0] => 42S22
        [1] => 1054
        [2] => Unknown column 'room.title' in 'field list'
    )
    Caused by: PDOException
    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'room.title' in 'field list'
    Ответ написан