Recess Developer Forums: Joins with aliases - Recess Developer Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Joins with aliases Join

#1 User is offline   SebastianJoseph Icon

  • Group: Members
  • Posts: 3
  • Joined: 29-June 10

Posted 29 June 2010 - 09:04 AM

Hi folks,
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 :)). I have only modified the joinHelper method of the sqlBuilder class.
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.
1

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users