eZ\Publish\Core\Persistence\Database\SelectQuery::alias PHP Method

alias() public method

This method can be used to create an alias for either a table or a column. Example: this will make the table users have the alias employees and the column user_id the alias employee_id $q->select( $q->alias( 'user_id', 'employee_id' ) ->from( $q->alias( 'users', 'employees' ) );
public alias ( string $name, string $alias ) : string
$name string
$alias string
return string the query string "columnname as targetname"
    public function alias($name, $alias);

Usage Example

 /**
  * Generate query expression for a Criterion this handler accepts.
  *
  * accept() must be called before calling this method.
  *
  * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter
  * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
  * @param array $languageSettings
  *
  * @return \eZ\Publish\Core\Persistence\Database\Expression
  */
 public function handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings)
 {
     switch ($criterion->target) {
         case Criterion\UserMetadata::MODIFIER:
             return $query->expr->in($this->dbHandler->quoteColumn('creator_id', 'ezcontentobject_version'), $criterion->value);
         case Criterion\UserMetadata::GROUP:
             $subSelect = $query->subSelect();
             $subSelect->select($this->dbHandler->quoteColumn('contentobject_id', 't1'))->from($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), 't1'))->innerJoin($query->alias($this->dbHandler->quoteTable('ezcontentobject_tree'), 't2'), $query->expr->like('t1.path_string', $query->expr->concat('t2.path_string', $query->bindValue('%'))))->where($query->expr->in($this->dbHandler->quoteColumn('contentobject_id', 't2'), $criterion->value));
             return $query->expr->in($this->dbHandler->quoteColumn('owner_id', 'ezcontentobject'), $subSelect);
         case Criterion\UserMetadata::OWNER:
             return $query->expr->in($this->dbHandler->quoteColumn('owner_id', 'ezcontentobject'), $criterion->value);
     }
     throw new RuntimeException("Invalid target criterion encountered:'" . $criterion->target . "'");
 }
All Usage Examples Of eZ\Publish\Core\Persistence\Database\SelectQuery::alias