Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Add JOIN support to JDatabaseQuery UPDATE query #547

Merged
merged 1 commit into from Nov 23, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions libraries/joomla/database/databasequery.php
Expand Up @@ -349,6 +349,16 @@ public function __toString()

case 'update':
$query .= (string) $this->update;

if ($this->join)
{
// special case for joins
foreach ($this->join as $join)
{
$query .= (string) $join;
}
}

$query .= (string) $this->set;

if ($this->where)
Expand Down
28 changes: 28 additions & 0 deletions tests/suite/joomla/database/JDatabaseQueryTest.php
Expand Up @@ -157,6 +157,34 @@ public function test__toStringSelect()
);
}

/**
* Test for the JDatabaseQuery::__string method for a 'update' case.
*
* @return void
*
* @since 11.3
*/
public function test__toStringUpdate()
{
$q = new JDatabaseQueryInspector($this->dbo);

$q->update('#__foo AS a')
->join('INNER', 'b ON b.id = a.id')
->set('a.id = 2')
->where('b.id = 1');

$this->assertThat(
(string) $q,
$this->equalTo(
"\nUPDATE #__foo AS a" .
"\nINNER JOIN b ON b.id = a.id" .
"\nSET a.id = 2" .
"\nWHERE b.id = 1"
),
'Tests for correct rendering.'
);
}

/**
* Test for the castAsChar method.
*
Expand Down