From 72e56808fbd472072301cce449787ffca727642c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 23 Dec 2021 09:14:58 +0100 Subject: [PATCH] wip #4977 @0.25 --- src/app/Magic/Fields/SelectFromModel.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/Magic/Fields/SelectFromModel.php b/src/app/Magic/Fields/SelectFromModel.php index 466d797..2d44b72 100644 --- a/src/app/Magic/Fields/SelectFromModel.php +++ b/src/app/Magic/Fields/SelectFromModel.php @@ -20,9 +20,27 @@ class SelectFromModel extends Model protected $_order = false; protected $_allows_null = false; + public function getDefaultAttributes() { - return array_merge(parent::getDefaultAttributes(), ['order' => $this->_order, 'allows_null' => $this->_allows_null]); + $field = $this; + + return array_merge(parent::getDefaultAttributes(), [ + 'order' => $this->_order, + 'allows_null' => $this->_allows_null, + 'searchLogic' => function ($query, $column, $searchTerm) use ($field) { + $pluckAttr = $field->getAttribute('column_attribute', $field->getAttribute('attribute')); + $list = $field->pluck($pluckAttr); + $findIds = []; + foreach ($list as $id => $value) { + if (stristr($value, $searchTerm)) { + $findIds[] = $id; + } + } + $query->orWhereIn($field->getName(), $findIds); + }, + ] + ); } protected function _preGetDefinition() -- 2.39.5