Example #1
0
 /**
  * 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;
 }
Example #2
0
	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);
		}
		
	}
Example #3
0
File: App.php Project: ricobl/frix
	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;
		
	}
Example #4
0
	static public function meta() {
		return ModelMeta::meta(get_class());
	}
Example #5
0
	function get_meta () {
		if (!$this->meta) {
			$this->meta = ModelMeta::meta($this->model_name);
		}
		return $this->meta;
	}
Example #6
0
    private function set_up () {
        if (!is_a($this->model_name, 'Model')) {
            $this->related_model = ModelMeta::meta($this->model_name);
        }
	}