lithium\data\model\Query::alias()
Get or Set a unique alias for the query or a query's relation if $relpath
is set.
Parameters
-
mixed
$alias
The value of the alias to set for the passed
$relpath
. For getting an alias value set alias totrue
. -
string
$relpath
A dotted relation name or
null
for identifying the query's model.
Returns
stringAn alias value or null
for an unexisting $relpath
alias.
Source
public function alias($alias = true, $relpath = null) {
if ($alias === true) {
if (!$relpath) {
return $this->_config['alias'];
}
$return = array_search($relpath, $this->_paths);
return $return ?: null;
}
if ($relpath === null) {
$this->_config['alias'] = $alias;
}
if ($relpath === null && ($model = $this->_config['model'])) {
$this->_models[$alias] = $model;
}
$relpath = (string) $relpath;
unset($this->_paths[array_search($relpath, $this->_paths)]);
if (!$alias && $relpath) {
$last = strrpos($relpath, '.');
$alias = $last ? substr($relpath, $last + 1) : $relpath;
}
if (isset($this->_alias[$alias])) {
$this->_alias[$alias]++;
$alias .= '__' . $this->_alias[$alias];
} else {
$this->_alias[$alias] = 1;
}
$this->_paths[$alias] = $relpath;
return $alias;
}