mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 17:42:41 +00:00
Adding condition for counterCache update keys. Fixes issues where counter cache wouldn't be updated. Fixes #450
This commit is contained in:
parent
e304c48ec4
commit
028668b7a6
2 changed files with 21 additions and 1 deletions
|
@ -1801,7 +1801,10 @@ class Model extends Overloadable {
|
|||
$this->id = $id;
|
||||
|
||||
if (!empty($this->belongsTo)) {
|
||||
$keys = $this->find('first', array('fields' => $this->__collectForeignKeys()));
|
||||
$keys = $this->find('first', array(
|
||||
'fields' => $this->__collectForeignKeys(),
|
||||
'conditions' => array($this->alias . '.' . $this->primaryKey => $id)
|
||||
));
|
||||
}
|
||||
|
||||
if ($db->delete($this)) {
|
||||
|
|
|
@ -255,6 +255,23 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that delete() updates the correct records counterCache() records.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteUpdatingCounterCacheCorrectly() {
|
||||
$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
|
||||
$User =& new CounterCacheUser();
|
||||
|
||||
$User->Post->delete(3);
|
||||
$result = $User->read(null, 301);
|
||||
$this->assertEqual($result['User']['post_count'], 0);
|
||||
|
||||
$result = $User->read(null, 66);
|
||||
$this->assertEqual($result['User']['post_count'], 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAll method
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue