Add support for morphOne relations in backend list columns (#4079)
Fixes #4078. Credit to @SeriousKen
This commit is contained in:
parent
da8073c945
commit
15bfcf8cfd
|
|
@ -350,6 +350,7 @@ class Lists extends WidgetBase
|
||||||
$selects = [$primaryTable.'.*'];
|
$selects = [$primaryTable.'.*'];
|
||||||
$joins = [];
|
$joins = [];
|
||||||
$withs = [];
|
$withs = [];
|
||||||
|
$bindings = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @event backend.list.extendQueryBefore
|
* @event backend.list.extendQueryBefore
|
||||||
|
|
@ -501,6 +502,11 @@ class Lists extends WidgetBase
|
||||||
$joinSql = $countQuery->select($joinSql)->toSql();
|
$joinSql = $countQuery->select($joinSql)->toSql();
|
||||||
|
|
||||||
$selects[] = Db::raw("(".$joinSql.") as ".$alias);
|
$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
|
* Primary column
|
||||||
|
|
@ -541,6 +547,11 @@ class Lists extends WidgetBase
|
||||||
*/
|
*/
|
||||||
$query->addSelect($selects);
|
$query->addSelect($selects);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add bindings for polymorphic relations
|
||||||
|
*/
|
||||||
|
$query->addBinding($bindings, 'select');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @event backend.list.extendQuery
|
* @event backend.list.extendQuery
|
||||||
* Provides an opportunity to modify and / or return the `$query` object after the List widget has applied its scopes to it and before it's used to get the records.
|
* Provides an opportunity to modify and / or return the `$query` object after the List widget has applied its scopes to it and before it's used to get the records.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue