BUGFIX: Throw an exception if you try an delete an unsaved or already-deleted record (from r106078)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112513 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 02:54:34 +00:00
parent b839ab2b9f
commit ee0d4c5197

View File

@ -1173,6 +1173,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
user_error("$this->class has a broken onBeforeDelete() function. Make sure that you call parent::onBeforeDelete().", E_USER_ERROR); user_error("$this->class has a broken onBeforeDelete() function. Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
} }
// Deleting a record without an ID shouldn't do anything
if(!$this->ID) throw new Exception("DataObject::delete() called on a DataObject without an ID");
foreach($this->getClassAncestry() as $ancestor) { foreach($this->getClassAncestry() as $ancestor) {
if(self::has_own_table($ancestor)) { if(self::has_own_table($ancestor)) {
$sql = new SQLQuery(); $sql = new SQLQuery();