Commit fe04e7d3 authored by Dries's avatar Dries

- Patch #793604 by matt2000, chx: DBTNG JOINs are close to useless.

parent a4954415
......@@ -232,7 +232,9 @@ public function addExpression($expression, $alias = NULL, $arguments = array());
* this clause should use a named placeholder and the value or values to
* insert should be passed in the 4th parameter. For the first table joined
* on a query, this value is ignored as the first table is taken as the base
* table.
* table. The token %alias can be used in this string to be replaced with
* the actual alias. This is useful when $alias is modified by the database
* system, for example, when joining the same table more than once.
* @param $arguments
* An array of arguments to replace into the $condition of this join.
* @return
......@@ -253,7 +255,9 @@ public function join($table, $alias = NULL, $condition = NULL, $arguments = arra
* this clause should use a named placeholder and the value or values to
* insert should be passed in the 4th parameter. For the first table joined
* on a query, this value is ignored as the first table is taken as the base
* table.
* table. The token %alias can be used in this string to be replaced with
* the actual alias. This is useful when $alias is modified by the database
* system, for example, when joining the same table more than once.
* @param $arguments
* An array of arguments to replace into the $condition of this join.
* @return
......@@ -274,7 +278,9 @@ public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments =
* this clause should use a named placeholder and the value or values to
* insert should be passed in the 4th parameter. For the first table joined
* on a query, this value is ignored as the first table is taken as the base
* table.
* table. The token %alias can be used in this string to be replaced with
* the actual alias. This is useful when $alias is modified by the database
* system, for example, when joining the same table more than once.
* @param $arguments
* An array of arguments to replace into the $condition of this join.
* @return
......@@ -295,7 +301,9 @@ public function leftJoin($table, $alias = NULL, $condition = NULL, $arguments =
* this clause should use a named placeholder and the value or values to
* insert should be passed in the 4th parameter. For the first table joined
* on a query, this value is ignored as the first table is taken as the base
* table.
* table. The token %alias can be used in this string to be replaced with
* the actual alias. This is useful when $alias is modified by the database
* system, for example, when joining the same table more than once.
* @param $arguments
* An array of arguments to replace into the $condition of this join.
* @return
......@@ -324,7 +332,9 @@ public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments =
* this clause should use a named placeholder and the value or values to
* insert should be passed in the 4th parameter. For the first table joined
* on a query, this value is ignored as the first table is taken as the base
* table.
* table. The token %alias can be used in this string to be replaced with
* the actual alias. This is useful when $alias is modified by the database
* system, for example, when joining the same table more than once.
* @param $arguments
* An array of arguments to replace into the $condition of this join.
* @return
......@@ -1210,6 +1220,10 @@ public function addJoin($type, $table, $alias = NULL, $condition = NULL, $argume
}
$alias = $alias_candidate;
if (is_string($condition)) {
$condition = str_replace('%alias', $alias, $condition);
}
$this->tables[$alias] = array(
'join type' => $type,
'table' => $table,
......
......@@ -1972,6 +1972,20 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$job = $query->execute()->fetchField();
$this->assertEqual($job, 'Songwriter', t('Correct data retrieved.'));
}
/**
* Confirm we can join on a single table twice with a dynamic alias.
*/
function testJoinTwice() {
$query = db_select('test')->fields('test');
$alias = $query->join('test', 'test', 'test.job = %alias.job');
$query->addField($alias, 'name', 'othername');
$query->addField($alias, 'job', 'otherjob');
$query->where("$alias.name <> test.name");
$crowded_job = $query->execute()->fetch();
$this->assertEqual($crowded_job->job, $crowded_job->otherjob, t('Correctly joined same table twice.'));
$this->assertNotEqual($crowded_job->name, $crowded_job->othername, t('Correctly joined same table twice.'));
}
}
class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment