Как выполнить такой запрос с помощю моделей Active Record?
SELECT rooms.id_room, rooms.number
FROM rooms
LEFT JOIN reservation ON rooms.id_room = reservation.id_room
WHERE rooms.id_room NOT IN (
SELECT reservation.id_room
FROM reservation
WHERE CURDATE() BETWEEN reservation.lock_start AND reservation.lock_finish
)
Делаю так но появляется ошыбка Undefined variable: rdRooms
public function getReservation()
{
return $this->hasMany(Reservation::className(), ['id_room' => 'id_room']);
}
............................................................................................................................
$rdRooms = (new Query)->select('reservation.id_room')
->from('reservation')
->where(':now BETWEEN reservation.lock_start AND reservation.lock_finish')
->addParams([':now' => date('Y-m-d')]);
$rooms = Rooms::find()->joinWith([
'reservation' => function ($query) {
$query->where(['rooms.id_room' => $rdRooms]);
}