Skip to content
Permalink
Browse files

Update Query usage in Table class.

The insert/delete/update methods no longer need table parameters, so
remove them where possible.

Refs #2550
  • Loading branch information...
markstory committed Dec 28, 2013
1 parent 1cd5f8d commit 9db42b1594c997296c0ccefe77243c054fd10e01
Showing with 12 additions and 8 deletions.
  1. +5 −5 Cake/ORM/Table.php
  2. +7 −3 Cake/Test/TestCase/ORM/TableTest.php
@@ -864,7 +864,7 @@ public function query() {
*/
public function updateAll($fields, $conditions) {
$query = $this->query();
$query->update($this->table())
$query->update()
->set($fields)
->where($conditions);
$statement = $query->execute();
@@ -957,7 +957,7 @@ public function validationDefault(Validator $validator) {
*/
public function deleteAll($conditions) {
$query = $this->query();
$query->delete($this->table())
$query->delete()
->where($conditions);
$statement = $query->execute();
$success = $statement->rowCount() > 0;
@@ -1188,7 +1188,7 @@ protected function _insert($entity, $data) {
$data[$primary] = $id;
}
$statement = $query->insert($this->table(), array_keys($data))
$statement = $query->insert(array_keys($data))
->values($data)
->execute();
@@ -1248,7 +1248,7 @@ protected function _update($entity, $data) {
}
$query = $this->query();
$statement = $query->update($this->table())
$statement = $query->update()
->set($data)
->where($primaryKey)
->execute();
@@ -1338,7 +1338,7 @@ protected function _processDelete($entity, $options) {
}
$query = $this->query();
$statement = $query->delete($this->table())
$statement = $query->delete()
->where($conditions)
->execute();
@@ -489,15 +489,17 @@ public function testUpdateAllFailure() {
$table = $this->getMock(
'Cake\ORM\Table',
['query'],
[['table' => 'users']]
[['table' => 'users', 'connection' => $this->connection]]
);
$query = $this->getMock('Cake\ORM\Query', ['_executeStatement'], [$this->connection, null]);
$query = $this->getMock('Cake\ORM\Query', ['_executeStatement'], [$this->connection, $table]);
$table->expects($this->once())
->method('query')
->will($this->returnValue($query));
$query->expects($this->once())
->method('_executeStatement')
->will($this->throwException(new \Cake\Database\Exception('Not good')));
$table->updateAll(['username' => 'mark'], []);
}
@@ -530,13 +532,15 @@ public function testDeleteAllFailure() {
['query'],
[['table' => 'users', 'connection' => $this->connection]]
);
$query = $this->getMock('Cake\ORM\Query', ['_executeStatement'], [$this->connection, null]);
$query = $this->getMock('Cake\ORM\Query', ['_executeStatement'], [$this->connection, $table]);
$table->expects($this->once())
->method('query')
->will($this->returnValue($query));
$query->expects($this->once())
->method('_executeStatement')
->will($this->throwException(new \Cake\Database\Exception('Not good')));
$table->deleteAll(['id >' => 4]);
}

0 comments on commit 9db42b1

Please sign in to comment.
You can’t perform that action at this time.