Skip to content
Permalink
Browse files

Prevent unnecessary joins / complex conditions in delete

  • Loading branch information...
mvdriel committed Jul 25, 2016
1 parent b50c064 commit d6e45131ad287e97c17d9b1c2bccb657c7cdc4d7
@@ -439,7 +439,7 @@ public function delete(Model $model, $conditions = null) {
}
$complexConditions = false;
foreach ((array)$conditions as $key => $value) {
if (strpos($key, $model->alias) === false) {
if (strpos($key, '.') !== false && strpos($key, $model->alias) === false) {
$complexConditions = true;
break;
}
@@ -4045,6 +4045,27 @@ public function testDeleteStatements() {
$this->Dbo->delete($Article, '2=2');
}
/**
* Test deletes without complex conditions.
*
* @return void
*/
public function testDeleteNoComplexCondition() {
$this->loadFixtures('Article', 'User');
$test = ConnectionManager::getDatasource('test');
$db = $test->config['database'];
$this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
$this->Dbo->expects($this->at(0))->method('execute')
->with("DELETE `Article` FROM `$db`.`articles` AS `Article` WHERE `id` = 1");
$Article = new Article();
$conditions = array('id' => 1);
$this->Dbo->delete($Article, $conditions);
}
/**
* Test truncate with a mock.
*

0 comments on commit d6e4513

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