Apply defined constraints to view mode

In the same way it is currently applied to manage mode
Fixes #2292
This commit is contained in:
Samuel Georges 2016-08-13 15:21:17 +10:00
parent c2d2250a1c
commit 618a035616
1 changed files with 21 additions and 1 deletions

View File

@ -621,10 +621,30 @@ class RelationController extends ControllerBehavior
$config->noRecordsMessage = $emptyMessage;
}
$widget = $this->makeWidget('Backend\Widgets\Lists', $config);
/*
* Apply defined constraints
*/
if ($sqlConditions = $this->getConfig('view[conditions]')) {
$widget->bindEvent('list.extendQueryBefore', function($query) use ($sqlConditions) {
$query->whereRaw($sqlConditions);
});
}
elseif ($scopeMethod = $this->getConfig('view[scope]')) {
$widget->bindEvent('list.extendQueryBefore', function($query) use ($scopeMethod) {
$query->$scopeMethod();
});
}
else {
$widget->bindEvent('list.extendQueryBefore', function($query) {
$this->relationObject->addDefinedConstraintsToQuery($query);
});
}
/*
* Constrain the query by the relationship and deferred items
*/
$widget = $this->makeWidget('Backend\Widgets\Lists', $config);
$widget->bindEvent('list.extendQuery', function ($query) {
$this->relationObject->setQuery($query);