From 618a03561643b4c24f99bff9838d9ef197bb37dc Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 13 Aug 2016 15:21:17 +1000 Subject: [PATCH] Apply defined constraints to view mode In the same way it is currently applied to manage mode Fixes #2292 --- .../backend/behaviors/RelationController.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 7bf18e8e8..b197f9fd8 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -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);