public function create_joins($joins)
{
if (!is_array($joins)) {
return $joins;
}
$ret = $space = '';
$existing_tables = array();
foreach ($joins as $value) {
$ret .= $space;
if (stripos($value, 'JOIN ') === false) {
if (array_key_exists($value, $this->relationships)) {
$rel = $this->get_relationship($value);
// if there is more than 1 join for a given table we need to alias the table names
if (array_key_exists($rel->class_name, $existing_tables)) {
$alias = $value;
$existing_tables[$rel->class_name]++;
} else {
$existing_tables[$rel->class_name] = true;
$alias = null;
}
$ret .= $rel->construct_inner_join_sql($this, false, $alias);
} else {
throw new RelationshipException("Relationship named {$value} has not been declared for class: {$this->class->getName()}");
}
} else {
$ret .= $value;
}
$space = ' ';
}
return $ret;
}