Fix warnings when deleting records that do not exist.

Fixes #3037
This commit is contained in:
mark_story 2012-07-14 15:54:07 -04:00
parent 6c905411ba
commit a7c79e5da2
2 changed files with 17 additions and 3 deletions

View file

@ -124,11 +124,13 @@ class TreeBehavior extends ModelBehavior {
*/
public function beforeDelete(Model $Model, $cascade = true) {
extract($this->settings[$Model->alias]);
$data = current($Model->find('first', array(
$data = $Model->find('first', array(
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right),
'recursive' => -1)));
$this->_deletedRow = $data;
'recursive' => -1));
if ($data) {
$this->_deletedRow = current($data);
}
return true;
}

View file

@ -914,6 +914,18 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->assertSame($validTree, true);
}
/**
* Test deleting a record that doesn't exist.
*
* @return void
*/
public function testDeleteDoesNotExist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$this->Tree->delete(99999);
}
/**
* testRemove method
*