mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Move the search term constraint under the same query group
Refs https://github.com/octobercms/october/pull/775
This commit is contained in:
parent
b806bd0720
commit
93dd61efc7
@ -361,25 +361,6 @@ class Lists extends WidgetBase
|
||||
$joins[] = $column->relation;
|
||||
}
|
||||
|
||||
/*
|
||||
* Include any relation constraints
|
||||
*/
|
||||
if ($joins) {
|
||||
foreach (array_unique($joins) as $join) {
|
||||
/*
|
||||
* Apply a supplied search term for relation columns and
|
||||
* constrain the query only if there is something to search for
|
||||
*/
|
||||
$columnsToSearch = array_get($relationSearchable, $join, []);
|
||||
|
||||
if (count($columnsToSearch) > 0) {
|
||||
$query->whereHas($join, function ($_query) use ($columnsToSearch) {
|
||||
$_query->searchWhere($this->searchTerm, $columnsToSearch);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add eager loads to the query
|
||||
*/
|
||||
@ -387,6 +368,39 @@ class Lists extends WidgetBase
|
||||
$query->with(array_unique($withs));
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply search term
|
||||
*/
|
||||
$query->where(function ($innerQuery) use ($primarySearchable, $relationSearchable, $joins) {
|
||||
|
||||
/*
|
||||
* Search primary columns
|
||||
*/
|
||||
if (count($primarySearchable) > 0) {
|
||||
$innerQuery->orSearchWhere($this->searchTerm, $primarySearchable);
|
||||
}
|
||||
|
||||
/*
|
||||
* Search relation columns
|
||||
*/
|
||||
if ($joins) {
|
||||
foreach (array_unique($joins) as $join) {
|
||||
/*
|
||||
* Apply a supplied search term for relation columns and
|
||||
* constrain the query only if there is something to search for
|
||||
*/
|
||||
$columnsToSearch = array_get($relationSearchable, $join, []);
|
||||
|
||||
if (count($columnsToSearch) > 0) {
|
||||
$innerQuery->orWhereHas($join, function ($_query) use ($columnsToSearch) {
|
||||
$_query->searchWhere($this->searchTerm, $columnsToSearch);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* Custom select queries
|
||||
*/
|
||||
@ -428,15 +442,6 @@ class Lists extends WidgetBase
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply a supplied search term for primary columns
|
||||
*/
|
||||
if (count($primarySearchable) > 0) {
|
||||
$query->where(function ($innerQuery) use ($primarySearchable) {
|
||||
$innerQuery->searchWhere($this->searchTerm, $primarySearchable);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Apply sorting
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user