From eb018ad36a9eb6833fb0aeae61fa21d14eef2690 Mon Sep 17 00:00:00 2001 From: Romain Louis Date: Mon, 21 Apr 2008 05:29:59 +0000 Subject: [PATCH] getParentIdNameRelation bug fixing and cleaning : This function is usefull only for the has_one and has_many relation but useless for many_many Morerover, it manages well now the child heritage and parent heritage git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53114 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/ComplexTableField.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index e3f078616..b7c170f97 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -630,16 +630,13 @@ JS; /** * Returns the db-fieldname of the currently used relationship. */ - function getParentIdNameRelation( $parentClass, $childClass, $relation ){ + function getParentIdNameRelation($parentClass, $childClass, $relation) { if($this->parentIdName) return $this->parentIdName; - $relations = singleton( $parentClass )->$relation(); - $classes = ClassInfo::ancestry( $childClass ); - foreach( $relations as $k => $v ) { - if( $v == $childClass ) - return $k . 'ID'; - else if( array_key_exists( $v, $classes ) ) - return $classes[ $v ] . 'ID'; + $relations = singleton($parentClass)->$relation(); + $classes = ClassInfo::ancestry($childClass); + foreach($relations as $k => $v) { + if(array_key_exists($v, $classes)) return $k . 'ID'; } return false; }