I am writing a management interface using recess at the moment. Therefor I needed aliases for joins, so that I could join one table multiple times. (Don't ask me why
Maybe it is helpful. If not, then ignore this post.
protected function joinHelper() {
$sql = '';
if(!empty($this->joins)) {
$joins = array_reverse($this->joins, true);
foreach($joins as $join) {
$joinStatement = ' ';
@list($joinTable, $joinAlias) = explode(' ', $join->table, 2);
if(isset($join->natural) && $join->natural != '') {
$joinStatement .= $join->natural . ' ';
}
if(isset($join->leftRightOrFull) && $join->leftRightOrFull != '') {
$joinStatement .= $join->leftRightOrFull . ' ';
}
if(isset($join->innerOuterOrCross) && $join->innerOuterOrCross != '') {
$joinStatement .= $join->innerOuterOrCross . ' ';
}
$onStatement = ' ON ' . self::escapeWithTicks($join->tablePrimaryKey) . ' = ' . self::escapeWithTicks($join->fromTableForeignKey);
$joinStatement .= 'JOIN ' . self::escapeWithTicks($joinTable) . (isset($joinAlias) ? ' AS '. self::escapeWithTicks($joinAlias) : '') . $onStatement;
$sql .= $joinStatement;
}
}
return $sql;
}Edit: Manual alias names for sure.

Sign In
Register
Help

MultiQuote