Prevent unnecessary joins / complex conditions in delete

This commit is contained in:
Mark van Driel 2016-07-25 17:15:18 +02:00
parent b50c06423d
commit d6e45131ad
2 changed files with 22 additions and 1 deletions

View file

@ -439,7 +439,7 @@ class Mysql extends DboSource {
}
$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;
}

View file

@ -4045,6 +4045,27 @@ SQL;
$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.
*