From a8371264dc7b3514b2f486ab3fed742145dfcb3e Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sun, 29 Jun 2014 09:12:11 +1000 Subject: [PATCH] Improve efficiency of List widget, empty relations now no longer try to load themselves and show empty JSON array "[]" --- modules/backend/widgets/Lists.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 890cf39fc..d7d285831 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -549,7 +549,16 @@ class Lists extends WidgetBase */ public function getColumnValue($record, $column) { - $value = $record->{$column->columnName}; + /* + * If the column is a relation, it will be a custom select, + * so prevent the Model from attempting to load the relation + * if the value is NULL. + */ + $columnName = $column->columnName; + if ($record->hasRelation($columnName) && array_key_exists($columnName, $record->attributes)) + $value = $record->attributes[$columnName]; + else + $value = $record->{$columnName}; if (method_exists($this, 'eval'. studly_case($column->type) .'TypeValue')) $value = $this->{'eval'. studly_case($column->type) .'TypeValue'}($value, $column);