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
This commit is contained in:
Romain Louis 2008-04-21 05:29:59 +00:00
parent c5c3cf19b6
commit eb018ad36a

View File

@ -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;
}