mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Prevent unnecessary joins / complex conditions in delete
This commit is contained in:
parent
b50c06423d
commit
d6e45131ad
2 changed files with 22 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue