I have a ‘reservation’ that has ‘reservationDetail’ records (each reservation has many reservationDetails). For some reason I can’t iterate through the list of detail records. Obviously I’m doing something wrong…
Reservation relations
public function relations()
{
return array(
'eventRecord' => array(self::BELONGS_TO, 'EventRecord', 'event_record_id'),
'reservationStatus' => array(self::BELONGS_TO, 'ReservationStatus', 'reservation_status_id'),
'reservationDetails' => array(self::HAS_MANY, 'ReservationDetail', 'reservation_id'),
);
}
ReservationDetail relations
public function relations()
{
return array(
'rate' => array(self::BELONGS_TO, 'Rate', 'rate_id'),
'reservation' => array(self::BELONGS_TO, 'Reservation', 'reservation_id'),
'rateClass'=>array(
self::HAS_ONE, 'RateClass', array('rate_class_id'=>'rate_class_id'), 'through'=>'rate')
);
}
I’m trying to do something like this:
$cleanUpMinutes = Config::getValue('reservation_timeout_minutes');
$criteria = new CDbCriteria();
$criteria->addCondition('reservation_status_id=3'); //3 = pending payment
$criteria->addCondition("NOW() > mod_date + INTERVAL $cleanUpMinutes MINUTE");
$staleReservations = Reservation::model()->with('reservationDetails')->findAll($criteria);
foreach($staleReservations as $reservation) {
//want to delete the detail records (reservationDetails) and the primary model here as well.
}
Trying to loop through the details keeps giving me “trying to get property of non-object” error. I think I have something wrong in my relations based on output of CVarDumper::dump of $staleReservations. I’m just a beginner, but it doesn’t look right…
Right now i have one record in reservation and 3 associated records in reservation detail.