BUGFIX: Throw an exception if you try an delete an unsaved or already-deleted record

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@106078 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-06-02 06:37:24 +00:00
parent 7cc9709123
commit e1753a35e5

View File

@ -1122,6 +1122,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);
}
// 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) {
if(self::has_own_table($ancestor)) {
$sql = new SQLQuery();