/** * Get AB_CustomerAppointment entities associated with this appointment. * * @return AB_CustomerAppointment[] Array of entities */ public function getCustomerAppointments() { $result = array(); if ($this->get('id')) { $appointments = AB_CustomerAppointment::query('ca')->select('ca.*, c.name, c.phone, c.email')->leftJoin('AB_Customer', 'c', 'c.id = ca.customer_id')->where('ca.appointment_id', $this->get('id'))->fetchArray(); foreach ($appointments as $data) { $ca = new AB_CustomerAppointment(); $ca->setFields($data); // Inject AB_Customer entity. $ca->customer = new AB_Customer(); $data['id'] = $data['customer_id']; $ca->customer->setFields($data, true); $result[] = $ca; } } return $result; }