/** * Sets the alias for this table * @param string $alias Alias for this table * @param zibo\library\orm\model\ModelMeta $meta Meta of the model of the query, to check if the alias is not a field name * @return null */ private function setAlias($alias, ModelMeta $meta = null) { if (String::isEmpty($alias)) { throw new OrmException('Provided alias is empty'); } if ($meta && $meta->hasField($alias)) { throw new OrmException('Provided alias is a field name of model ' . $meta->getName()); } $this->alias = $alias; }
function __construct ($obj) { // Figure out what kind of object we're using // ModelMeta: use it if (is_a($obj, 'ModelMeta')) { $this->meta = $obj; } // Model: use it's meta and keep the instance elseif (is_a($obj, 'Model')) { $this->meta = $obj->meta(); $this->instance = $obj; } // Other (string?): get the ModelMeta based on Model name else { $this->meta = ModelMeta::meta($obj); } }
public function load_model ($name) { /* if (!array_key_exists($name, $this->models) { return false; // TODO: maybe throw an exception here... // throw new Exception(sprintf('Model "%s" not available.', $name)); } */ $ok = import(join_path(array($this->models_path, $name . '.php'))); // Make a shortcut for the app on the model ModelMeta::meta($name)->app = $this; return $ok; }
static public function meta() { return ModelMeta::meta(get_class()); }
function get_meta () { if (!$this->meta) { $this->meta = ModelMeta::meta($this->model_name); } return $this->meta; }
private function set_up () { if (!is_a($this->model_name, 'Model')) { $this->related_model = ModelMeta::meta($this->model_name); } }