public function get_linked_models($modelName, $foreignKey, $reverse) { $model = Model::get_model_for($modelName); $result = array(); if (!$reverse) { if ($this->get_real_name($foreignKey) == null) { throw new Exception("'{$foreignKey}' is not a valid field name!"); } $result = $model->findBy("id", $this->{$foreignKey}); } else { $fields = (array) $this; if (!in_array("id", array_keys($fields))) { throw new Exception("'ID' has not been set for the current object and consequently linked models cannot be fetched."); } $result = $model->findBy($foreignKey, $this->id); } if (sizeof($result) == 0) { return null; } return $result; }