mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: add "InnerJoin" clause for an component's ancestry classes for SearchFilter::applyRelation() so that an searchfliter could filter on that component's ancestry's field.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@83500 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3c5f477b6e
commit
efbfb4a5f2
@ -127,6 +127,24 @@ abstract class SearchFilter extends Object {
|
|||||||
if(!$query->isJoinedTo($component)) {
|
if(!$query->isJoinedTo($component)) {
|
||||||
$foreignKey = $model->getReverseAssociation($component);
|
$foreignKey = $model->getReverseAssociation($component);
|
||||||
$query->leftJoin($component, "\"$component\".\"ID\" = \"{$this->model}\".\"{$foreignKey}ID\"");
|
$query->leftJoin($component, "\"$component\".\"ID\" = \"{$this->model}\".\"{$foreignKey}ID\"");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add join clause to the component's parent class so that the search filter could search on its
|
||||||
|
* parent fields.
|
||||||
|
* todo: add UT for this. Also add the clause for other relations like has_many, many_many in other
|
||||||
|
* elseif branch and their UTs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$ancestry = ClassInfo::ancestry($component, true);
|
||||||
|
if(!empty($ancestry)){
|
||||||
|
$ancestry = array_reverse($ancestry);
|
||||||
|
foreach($ancestry as $ancestor){
|
||||||
|
if($ancestor != $component){
|
||||||
|
$query->innerJoin($ancestor, "\"$component\".\"ID\" = \"$ancestor\".ID");
|
||||||
|
$component=$ancestor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->model = $component;
|
$this->model = $component;
|
||||||
} elseif ($component = $model->has_many($rel)) {
|
} elseif ($component = $model->has_many($rel)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user