Skip to content

Commit

Permalink
Update Query usage in Table class.
Browse files Browse the repository at this point in the history
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 9db42b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Cake/ORM/Table.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1338,7 +1338,7 @@ protected function _processDelete($entity, $options) {
}

$query = $this->query();
$statement = $query->delete($this->table())
$statement = $query->delete()
->where($conditions)
->execute();

Expand Down
10 changes: 7 additions & 3 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -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'], []);
}

Expand Down Expand Up @@ -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]);
}

Expand Down

0 comments on commit 9db42b1

Please sign in to comment.