Skip to content

Commit

Permalink
Make assotiation match for autocomplete fields a little more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewis-everley committed Nov 1, 2018
1 parent 9746a97 commit f9fc50b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@

## 1.0.6

* Auto convert search `TextField`s to use `AutoCompleteField`
* Auto convert search `TextField`s to use `AutoCompleteField`

## 1.0.7

* Improve resiliency of matching `AutoCompleteField`s on assotiations
7 changes: 4 additions & 3 deletions src/ModelAdminPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public function SearchForm()
// Change currently scaffolded query fields to use conventional
// field names
foreach ($fields as $field) {
$field_class = $this->modelClass;
$name = $field->getName();
$title = $field->Title();
$in_db = false;
Expand All @@ -321,9 +322,9 @@ public function SearchForm()
// If this is a relation, switch class name
if (strpos($name, "__")) {
$parts = explode("__", $db_field);
$class = $associations[$parts[0]];
$field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null;
$db_field = $parts[1];
$in_db = true;
$in_db = ($field_class) ? true : false;
}

// If this is in the DB (not casted)
Expand All @@ -338,7 +339,7 @@ public function SearchForm()
$name,
$title,
$field->Value(),
$class,
$field_class,
$db_field
)->setForm($form)
->setDisplayField($db_field)
Expand Down

0 comments on commit f9fc50b

Please sign in to comment.