diff --git a/core/metamodel.class.php b/core/metamodel.class.php index c5e69fbc2..6dfe213e4 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -5138,6 +5138,12 @@ abstract class MetaModel } return $aResult; } + + /** + * It is not recommended to use this function: call GetLinkClasses instead + * Return classes having at least to external keys (thus too many classes as compared to GetLinkClasses) + * The only difference with EnumLinkingClasses is the output format + */ public static function EnumLinksClasses() { // Returns a flat array of classes having at least two external keys @@ -5160,6 +5166,11 @@ abstract class MetaModel } return $aResult; } + /** + * It is not recommended to use this function: call GetLinkClasses instead + * Return classes having at least to external keys (thus too many classes as compared to GetLinkClasses) + * The only difference with EnumLinksClasses is the output format + */ public static function EnumLinkingClasses($sClass = "") { // N-N links, array of sLinkClass => (array of sAttCode=>sClass) @@ -5196,6 +5207,38 @@ abstract class MetaModel return $aResult; } + /** + * This function has two siblings that will be soon deprecated: + * EnumLinkingClasses and EnumLinkClasses + * + * Using GetLinkClasses is the recommended way to determine if a class is + * actually an N-N relation because it is based on the decision made by the + * designer the data model + */ + public static function GetLinkClasses() + { + $aRet = array(); + foreach(self::GetClasses() as $sClass) + { + if (isset(self::$m_aClassParams[$sClass]["is_link"])) + { + if (self::$m_aClassParams[$sClass]["is_link"]) + { + $aExtKeys = array(); + foreach (self::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) + { + if ($oAttDef->IsExternalKey()) + { + $aExtKeys[$sAttCode] = $oAttDef->GetTargetClass(); + } + } + $aRet[$sClass] = $aExtKeys; + } + } + } + return $aRet; + } + public static function GetLinkLabel($sLinkClass, $sAttCode) { self::_check_subclass($sLinkClass); diff --git a/core/modelreflection.class.inc.php b/core/modelreflection.class.inc.php index 338460957..9142f8414 100644 --- a/core/modelreflection.class.inc.php +++ b/core/modelreflection.class.inc.php @@ -178,7 +178,7 @@ class ModelReflectionRuntime extends ModelReflection $aClasses = MetaModel::GetClasses($sCategories); if ($bExcludeLinks) { - $aExcluded = ProfilesConfig::GetLinkClasses(); // table computed at compile time + $aExcluded = MetaModel::GetLinkClasses(); $aRes = array(); foreach ($aClasses as $sClass) { diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index 17491df08..82747ba79 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -617,7 +617,11 @@ EOF; $aClassParams = array(); $aClassParams['category'] = $this->GetPropString($oProperties, 'category', ''); $aClassParams['key_type'] = "'autoincrement'"; - + if ((bool) $this->GetPropNumber($oProperties, 'is_link', 0)) + { + $aClassParams['is_link'] = 'true'; + } + if ($oNaming = $oProperties->GetOptionalElement('naming')) { $oNameAttributes = $oNaming->GetUniqueElement('attributes'); @@ -1462,6 +1466,8 @@ class ProfilesConfig protected static \$aLINKTOCLASSES = $sLinkToClasses; + // Now replaced by MetaModel::GetLinkClasses (working with 1.x) + // This function could be deprecated public static function GetLinkClasses() { return self::\$aLINKTOCLASSES;