N°659 uniqueness constraint : fix class used in the dict key for the error message

It has to be the rule root class, not the current class
This commit is contained in:
Pierre Goiffon
2018-11-23 09:43:28 +01:00
parent e4912ee175
commit c242f90440
2 changed files with 31 additions and 3 deletions

View File

@@ -534,7 +534,7 @@ abstract class MetaModel
*
* @since 2.6 N°659 uniqueness constraint
*/
final static public function GetUniquenessRules($sClass)
final public static function GetUniquenessRules($sClass)
{
if (!isset(self::$m_aClassParams[$sClass]))
{
@@ -581,6 +581,33 @@ abstract class MetaModel
return $aCurrentUniquenessRules;
}
/**
* @param string $sRuleId
* @param string $sLeafClassName
*
* @return string name of the class, null if not present
*/
final public static function GetRootClassForUniquenessRule($sRuleId, $sLeafClassName)
{
$sFirstClassWithRuleId = null;
if (isset(self::$m_aClassParams[$sLeafClassName]['uniqueness_rules'][$sRuleId]))
{
$sFirstClassWithRuleId = $sLeafClassName;
}
$sParentClass = self::GetParentClass($sLeafClassName);
if ($sParentClass)
{
$sParentClassWithRuleId = self::GetRootClassForUniquenessRule($sRuleId, $sParentClass);
if (!is_null($sParentClassWithRuleId))
{
$sFirstClassWithRuleId = $sParentClassWithRuleId;
}
}
return $sFirstClassWithRuleId;
}
/**
* @param array $aRuleProperties
*