From 15bfcf8cfd079b27434db723fa7363d159fc0192 Mon Sep 17 00:00:00 2001 From: SeriousKen Date: Fri, 19 Apr 2019 23:31:12 +0100 Subject: [PATCH] Add support for morphOne relations in backend list columns (#4079) Fixes #4078. Credit to @SeriousKen --- modules/backend/widgets/Lists.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 102ab2eea..67fa2f322 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -350,6 +350,7 @@ class Lists extends WidgetBase $selects = [$primaryTable.'.*']; $joins = []; $withs = []; + $bindings = []; /** * @event backend.list.extendQueryBefore @@ -501,6 +502,11 @@ class Lists extends WidgetBase $joinSql = $countQuery->select($joinSql)->toSql(); $selects[] = Db::raw("(".$joinSql.") as ".$alias); + + /* + * If this is a polymorphic relation there will be bindings that need to be added to the query + */ + $bindings = array_merge($bindings, $countQuery->getBindings()); } /* * Primary column @@ -540,6 +546,11 @@ class Lists extends WidgetBase * Add custom selects */ $query->addSelect($selects); + + /* + * Add bindings for polymorphic relations + */ + $query->addBinding($bindings, 'select'); /** * @event backend.list.extendQuery