/** * @brief Magic method override. * * @param string $name - method to call * @param array $arguments - parameters for method * @return mixed - instance of a ORM_Base derived class | array of ORM_Wrapper | unknown * @throws Exception - if unable to identify/locate the method $name */ public function __call($name, $arguments) { // One to many if (isset($this->_to_many[$name])) { // Return wrapper $return = new ORMWrapper(); // Get model records $prepare = self::$instance->prepare("SELECT * FROM `{$this->_to_many[$name]}` WHERE `{$this->_get_table_name()}_id` = :object_id"); if ($prepare->execute(array('object_id' => $this->_data["{$this->_get_table_name()}_id"]))) { $model_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->_to_many[$name]))); while ($data = $prepare->fetch(\PDO::FETCH_ASSOC)) { eval('$object = ' . $model_name . '::load(' . $data[$name . "_id"] . ', $data);'); $return->push($object); } } return $return; } // One to one if (isset($this->_to_one[$name])) { $model_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->_to_one[$name]))); eval('$return = ' . $model_name . '::load(' . $this->_data[$name . "_id"] . ');'); return $return; } throw new ORMException(ORM::$exception_strings[400], 400); }