Fixed a regression in the deletion (and simplified the algorithm, though more queries will be issued)

SVN:trunk[1142]
This commit is contained in:
Romain Quetiez
2011-03-23 08:38:49 +00:00
parent 8f4ee29c69
commit 3790c8f7d5
2 changed files with 29 additions and 5 deletions

View File

@@ -1183,18 +1183,37 @@ abstract class DBObject
}
}
private function DBDeleteSingleTable($sTableClass)
{
$sTable = MetaModel::DBGetTable($sTableClass);
// Abstract classes or classes having no specific attribute do not have an associated table
if ($sTable == '') return;
$sPKField = '`'.MetaModel::DBGetKey($sTableClass).'`';
$sKey = CMDBSource::Quote($this->m_iKey);
$sDeleteSQL = "DELETE FROM `$sTable` WHERE $sPKField = $sKey";
CMDBSource::DeleteFrom($sDeleteSQL);
}
private function DBDeleteInternal()
{
$sClass = get_class($this);
foreach(MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL) as $sParentClass)
{
$this->DBDeleteSingleTable($sParentClass);
}
}
// Delete a record
public function DBDelete()
{
$oFilter = new DBObjectSearch(get_class($this));
$oFilter->AddCondition('id', $this->m_iKey, '=');
$this->OnDelete();
$sSQL = MetaModel::MakeDeleteQuery($oFilter);
if (!MetaModel::DBIsReadOnly())
{
CMDBSource::Query($sSQL);
$this->DBDeleteInternal();
}
$this->AfterDelete();