mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Commits to solve a ManyManyComplexTable problem with heritage
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@43892 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
07b0d18fa7
commit
0eafb6d08e
@ -2,18 +2,28 @@
|
|||||||
|
|
||||||
class ManyManyComplexTableField extends HasManyComplexTableField {
|
class ManyManyComplexTableField extends HasManyComplexTableField {
|
||||||
|
|
||||||
protected $itemClass = 'ManyManyComplexTableField_Item';
|
private $manyManyParentClass;
|
||||||
|
|
||||||
|
protected $itemClass = 'ManyManyComplexTableField_Item';
|
||||||
|
|
||||||
function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
||||||
|
|
||||||
parent::__construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin );
|
parent::__construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin );
|
||||||
|
|
||||||
$parent = $this->controller->ClassName;
|
$classes = array_reverse( ClassInfo::ancestry( $this->controller->ClassName ) );
|
||||||
$manyManyTable = $parent . '_' . $this->name;
|
foreach( $classes as $class ) {
|
||||||
|
$singleton = singleton( $class );
|
||||||
|
$manyManyRelations = $singleton->uninherited( 'many_many', true );
|
||||||
|
if( isset( $manyManyRelations ) && array_key_exists( $this->name, $manyManyRelations ) ) {
|
||||||
|
$this->manyManyParentClass = $class;
|
||||||
|
$manyManyTable = $class . '_' . $this->name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
$source = $this->sourceClass;
|
$source = $this->sourceClass;
|
||||||
$parentID = $this->controller->ID;
|
$parentID = $this->controller->ID;
|
||||||
|
|
||||||
$this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON ( `$source`.`ID` = `{$source}ID` AND `{$parent}ID` = '$parentID' )";
|
$this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON ( `$source`.`ID` = `{$source}ID` AND `{$this->manyManyParentClass}ID` = '$parentID' )";
|
||||||
|
|
||||||
$this->joinField = 'Checked';
|
$this->joinField = 'Checked';
|
||||||
}
|
}
|
||||||
@ -36,7 +46,7 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
|
|||||||
$query->select[] = $k;
|
$query->select[] = $k;
|
||||||
}
|
}
|
||||||
$parent = $this->controller->ClassName;
|
$parent = $this->controller->ClassName;
|
||||||
$query->select[] = "IF(`{$parent}ID` IS NULL, '0', '1') AS $this->joinField";
|
$query->select[] = "IF(`{$this->manyManyParentClass}ID` IS NULL, '0', '1') AS $this->joinField";
|
||||||
}
|
}
|
||||||
return clone $query;
|
return clone $query;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user