mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed bug where deleteAll tried to delete same id multiple times.
Ensure find done in deleteAll only returns distinct ids. A wacky combination of association and conditions can sometimes generate multiple rows per id.
This commit is contained in:
parent
b8268cd055
commit
f3900e89fd
2 changed files with 38 additions and 1 deletions
|
@ -2699,7 +2699,7 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
|
||||
$ids = $this->find('all', array_merge(array(
|
||||
'fields' => "{$this->alias}.{$this->primaryKey}",
|
||||
'fields' => "DISTINCT {$this->alias}.{$this->primaryKey}",
|
||||
'recursive' => 0), compact('conditions'))
|
||||
);
|
||||
|
||||
|
|
|
@ -454,6 +454,43 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAllMultipleRowsPerId method
|
||||
*
|
||||
* Ensure find done in deleteAll only returns distinct ids. A wacky combination
|
||||
* of association and conditions can sometimes generate multiple rows per id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteAllMultipleRowsPerId() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
|
||||
$TestModel = new Article();
|
||||
$TestModel->unbindModel(array(
|
||||
'belongsTo' => array('User'),
|
||||
'hasMany' => array('Comment'),
|
||||
'hasAndBelongsToMany' => array('Tag')
|
||||
), false);
|
||||
$TestModel->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
'User' => array(
|
||||
'foreignKey' => false,
|
||||
'conditions' => array(
|
||||
'Article.user_id = 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
), false);
|
||||
|
||||
$result = $TestModel->deleteAll(
|
||||
array('Article.user_id' => array(1, 3)),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRecursiveDel method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue