public $relationships = array();
/**
- * @var array
+ * @var integer
*/
- protected $_sortby = array();
+ public $limit;
/**
* @var integer
*/
- public $limit;
+ public $limitOffset = null;
+
+ /**
+ * @var array
+ */
+ protected $_sortby = array();
/**
* @var integer
*/
- public $limitOffset = null;
+ protected $_alias = 0;
/**
* Turn any of the acceptable query shorthands into a full
{
foreach ($this->relationships as $relationship) {
$relsql = array();
+ $table = $relationship['table'];
+ $tableAlias = $this->_alias($table);
foreach ($relationship['query'] as $key => $value) {
if ($value instanceof Horde_Rdo_Query_Literal) {
- $relsql[] = $key . ' = ' . (string)$value;
+ $relsql[] = $key . ' = ' . str_replace("{$table}.", "{$tableAlias}.", (string)$value);
} else {
$relsql[] = $key . ' = ?';
$bindParams[] = $value;
}
}
- $sql .= ' ' . $relationship['join_type'] . ' ' . $relationship['table'] . ' ON ' . implode(' AND ', $relsql);
+ $sql .= ' ' . $relationship['join_type'] . ' ' . $relationship['table'] . ' AS ' . $tableAlias . ' ON ' . implode(' AND ', $relsql);
}
}
}
/**
+ * Get a unique table alias
+ */
+ protected function _alias($tableName)
+ {
+ return 't' . $this->_alias;
+ }
+
+ /**
* Take a query array and replace @field@ placeholders with values
* that will match in the load query.
*