From cca8da2af3b329797b6da366180c61c0859bf55d Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Fri, 13 Mar 2020 07:47:01 +0800 Subject: [PATCH] Get correct model when not using ID for "keyFrom" in Record Finder (#4977) getLoadValue() was previously using the find method for getting the selected model on load when not using the Record Finder in relation mode. This means it was searching by the primary key, regardless of whether the keyFrom setting on the Record Finder widget was changed. This has the effect of the keyFrom setting being correctly used to determine the value of the record finder field when a model is selected, but the widget being unable to find the model when it refreshes or reloads. This change instead searches for the field's value in the column specified for the keyFrom setting, allowing us to use a different identifying column for loading the selected record. --- modules/backend/formwidgets/RecordFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/backend/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 4aed505e8..b02e3ab4d 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -252,7 +252,7 @@ class RecordFinder extends FormWidgetBase $value = $model->{$attribute}; } } else { - $value = $this->modelClass::find(parent::getLoadValue()); + $value = $this->modelClass::where($this->keyFrom, parent::getLoadValue())->first(); } return $value;