Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #547 from mbabker/updateJoin

Add JOIN statement to UPDATE query
  • Loading branch information...
commit 94b090380d58e41f0fdab64b5242105b2cb2772a 2 parents 53ae34b + 196d70f
@eddieajau eddieajau authored
View
10 libraries/joomla/database/databasequery.php
@@ -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)
View
28 tests/suite/joomla/database/JDatabaseQueryTest.php
@@ -158,6 +158,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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.