/** Create join string * @return string */ private function createJoin($clause, $mainTable, $joinTable, $joinAlias = '') { if (in_array(substr($mainTable, -1), array(':', '.'))) { $mainTable = substr($mainTable, 0, -1); } $referenceDirection = substr($joinTable, -1); $joinTable = substr($joinTable, 0, -1); $asJoinAlias = ''; if ($joinAlias) { $asJoinAlias = " AS {$joinAlias}"; if (!in_array($joinAlias, $this->createdAliases)) { $this->createdAliases[] = $joinAlias; } } else { $joinAlias = $joinTable; } if ($referenceDirection == ':') { # back reference $primaryKey = $this->structure->getPrimaryKey($mainTable); $foreignKey = $this->structure->getForeignKey($mainTable); return " {$clause} {$joinTable}{$asJoinAlias} ON {$joinAlias}.{$foreignKey} = {$mainTable}.{$primaryKey}"; } else { $primaryKey = $this->structure->getPrimaryKey($joinTable); $foreignKey = $this->structure->getForeignKey($joinTable); return " {$clause} {$joinTable}{$asJoinAlias} ON {$joinAlias}.{$primaryKey} = {$mainTable}.{$foreignKey}"; } }