From 5ec83b9bd00eabeb68ffe0168b2c1cd6cfae11d2 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 15 Oct 2009 22:38:57 +0000 Subject: [PATCH] BUGFIX: Fixed resolution of amibiguous has_many foreign keys in ComplexTableField to use the same logic as DataObject (from r88945) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89203 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/ComplexTableField.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 5c2e5fe61..6fab8aa05 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -427,16 +427,17 @@ JS; /** * Returns the db-fieldname of the currently used relationship. + * Note: constructed resolve ambiguous cases in the same manner as + * DataObject::getComponentJoinField() */ function getParentIdNameRelation($parentClass, $childClass, $relation) { if($this->parentIdName) return $this->parentIdName; - $relations = singleton($parentClass)->$relation(); - $classes = ClassInfo::ancestry($childClass); - if($relations) { - foreach($relations as $k => $v) { - if(array_key_exists($v, $classes)) return $k . 'ID'; - } + $relations = array_flip(singleton($parentClass)->$relation()); + + $classes = array_reverse(ClassInfo::ancestry($childClass)); + foreach($classes as $class) { + if(isset($relations[$class])) return $relations[$class] . 'ID'; } return false; }