From e9f707e48081608dc7227caffde2c22e8985a0a1 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 24 Jan 2012 13:07:05 +0000 Subject: [PATCH] Improved the check on data model consistency: detection of SQL columns used by two attributes SVN:trunk[1802] --- core/metamodel.class.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 15538f8472..6b7c97bf12 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -3064,7 +3064,36 @@ abstract class MetaModel } } } - } + + // Check unicity of the SQL columns + // + if (self::HasTable($sClass)) + { + $aTableColumns = array(); // array of column => attcode (the column is used by this attribute) + $aTableColumns[self::DBGetKey($sClass)] = 'id'; + + // Check that SQL columns are declared only once + // + foreach(self::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) + { + // Skip this attribute if not originaly defined in this class + if (self::$m_aAttribOrigins[$sClass][$sAttCode] != $sClass) continue; + + foreach($oAttDef->GetSQLColumns() as $sField => $sDBFieldType) + { + if (array_key_exists($sField, $aTableColumns)) + { + $aErrors[$sClass][] = "Column '$sField' declared for attribute $sAttCode, but already used for attribute ".$aTableColumns[$sField]; + $aSugFix[$sClass][] = "Please find another name for the SQL column"; + } + else + { + $aTableColumns[$sField] = $sAttCode; + } + } + } + } + } // foreach class if (count($aErrors) > 0) {