Merge pull request #8793 from wilr/pulls/orm-exception

Throw error message when searchable_field does not return a object
This commit is contained in:
Guy Marriott 2019-03-06 08:50:50 +13:00 committed by GitHub
commit f8f6983773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -2260,7 +2260,15 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
// Otherwise, use the database field's scaffolder
} elseif ($object = $this->relObject($fieldName)) {
$field = $object->scaffoldSearchField();
if (is_object($object) && $object->hasMethod('scaffoldSearchField')) {
$field = $object->scaffoldSearchField();
} else {
throw new Exception(sprintf(
"SearchField '%s' on '%s' does not return a valid DBField instance.",
$fieldName,
get_class($this)
));
}
}
// Allow fields to opt out of search