From 3b1902ed1a856354676ec4c449b6eb68f6f7400a Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 12 Sep 2022 20:59:27 -0300 Subject: [PATCH] Include AND when not specified in condition --- src/Alias/Database/Query/Select.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Alias/Database/Query/Select.php b/src/Alias/Database/Query/Select.php index f2ba809..7dd00cc 100644 --- a/src/Alias/Database/Query/Select.php +++ b/src/Alias/Database/Query/Select.php @@ -105,7 +105,19 @@ abstract class Select extends Query implements SelectInterface } public function getJoinString(): string { - return implode(' ', $this->getJoins()); + $str = []; + foreach ($this->getJoins() as $i => $join) { + if ($i === 0) { + $str []= $join; + continue; + } + if (!str_contains('and ', strtolower($join)) and !str_contains('or ', strtolower($join))) { + $str []= "AND {$join}"; + continue; + } + $str []= $join; + } + return implode(' ', $str); } protected array $conditions; public function setConditions(array $conditions): SelectInterface @@ -126,7 +138,19 @@ abstract class Select extends Query implements SelectInterface } public function getConditionString(): string { - return implode(' ', $this->getConditions()); + $str = []; + foreach ($this->getConditions() as $i => $condition) { + if ($i === 0) { + $str []= $condition; + continue; + } + if (!str_contains('and ', strtolower($condition)) and !str_contains('or ', strtolower($condition))) { + $str []= "AND {$condition}"; + continue; + } + $str []= $condition; + } + return implode(' ', $str); } protected array $groups; public function setGroups(array $groups): SelectInterface