BUGFIX Making sure that Dataobject->getManyManyJoin() inserts a valid database table for the relation - not all component classes returned by ComponentSet->ownerClass are valid tables (see r54797 and r60909 for previous commits on this issue)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63621 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-03 16:11:46 +00:00
parent 370343016f
commit 1307d3da41

View File

@ -1266,10 +1266,11 @@ class DataObject extends ViewableData implements DataObjectInterface {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName);
$baseComponentClass = ClassInfo::baseDataClass($componentClass);
if($baseTable == $parentClass) {
return "LEFT JOIN `$table` ON (`$table`.`$parentField` = `$parentClass`.`ID` AND `$table`.`$componentField` = '{$this->ID}')";
} else {
return "LEFT JOIN `$table` ON (`$table`.`$componentField` = `$componentClass`.`ID` AND `$table`.`$parentField` = '{$this->ID}')";
return "LEFT JOIN `$table` ON (`$table`.`$componentField` = `$baseComponentClass`.`ID` AND `$table`.`$parentField` = '{$this->ID}')";
}
}