Browse Source

Merge pull request #6462 from cakephp/orm-query-update

Adding a test to show it is possible to pass an expression in Query::update
Mark Story 11 years ago
parent
commit
bc2d222941
1 changed files with 21 additions and 0 deletions
  1. 21 0
      tests/TestCase/ORM/QueryTest.php

+ 21 - 0
tests/TestCase/ORM/QueryTest.php

@@ -1538,6 +1538,27 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Test update method.
+     *
+     * @return void
+     */
+    public function testUpdateWithTableExpression()
+    {
+        $this->skipIf(!$this->connection->driver() instanceof \Cake\Database\Driver\Mysql);
+        $table = TableRegistry::get('articles');
+
+        $query = $table->query();
+        $result = $query->update($query->newExpr('articles, authors'))
+            ->set(['title' => 'First'])
+            ->where(['articles.author_id = authors.id'])
+            ->andWhere(['authors.name' => 'mariano'])
+            ->execute();
+
+        $this->assertInstanceOf('Cake\Database\StatementInterface', $result);
+        $this->assertTrue($result->rowCount() > 0);
+    }
+
+    /**
      * Test insert method.
      *
      * @return void