fix: passing empty array to where() throws (#21)

This commit is contained in:
Victor Westerlund 2023-11-03 13:40:54 +01:00 committed by GitHub
parent f9ec906414
commit d9f450112e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,7 @@
}
// Create a WHERE statement from filters
public function where(?array ...$conditions): self {
public function where(array ...$conditions): self {
$values = [];
$filters = [];
@ -80,6 +80,11 @@
foreach ($conditions as $condition) {
$filter = [];
// Move along if the condition is empty
if (empty($condition)) {
continue;
}
// Create SQL string and append values to array for prepared statement
foreach ($condition as $col => $value) {
if ($this->model && !$this->in_model($col)) {
@ -96,6 +101,11 @@
$filters[] = "(" . implode(" AND ", $filter) . ")";
}
// Do nothing if no filters were set
if (empty($filters)) {
return $this;
}
// OR all filter groups
$this->filter_sql = implode(" OR ", $filters);
// Set values property