Permalink
Browse files

Fix warnings when deleting records that do not exist.

Fixes #3037
  • Loading branch information...
markstory committed Jul 14, 2012
1 parent 6c90541 commit a7c79e5da2fd3948fe5fdf0989c222c6c1a38006
@@ -124,11 +124,13 @@ public function beforeFind(Model $Model, $query) {
*/
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;
}
@@ -914,6 +914,18 @@ public function testDelete() {
$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
*

0 comments on commit a7c79e5

Please sign in to comment.