Skip to content

Commit 120a807

Browse files
committed
spqb
1 parent b461f05 commit 120a807

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

SimplePDOQueryBuilder.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class SimplePDOQueryBuilder
3939
*/
4040
protected $joins = [];
4141

42+
/**
43+
* @var array
44+
*/
45+
protected $leftJoins = [];
46+
4247
/**
4348
* @var
4449
*/
@@ -157,9 +162,9 @@ public function from($from)
157162
public function leftJoin($leftJoin, $condition = '')
158163
{
159164
if ($leftJoin instanceof SimplePDOQueryBuilder) {
160-
$this->joins[] = "\n LEFT JOIN ( {$leftJoin->getSql()} ) as {$leftJoin->getAlias()} ON $condition";
165+
$this->leftJoins[] = "\n LEFT JOIN ( {$leftJoin->getSql()} ) as {$leftJoin->getAlias()} ON $condition";
161166
} else {
162-
$this->joins[] = "\n LEFT JOIN " . $leftJoin . ($condition ? ' ON ' . $condition : '');
167+
$this->leftJoins[] = "\n LEFT JOIN " . $leftJoin . ($condition ? ' ON ' . $condition : '');
163168
}
164169
return $this;
165170
}
@@ -257,6 +262,9 @@ public function getSql()
257262
if (!empty($this->joins)) {
258263
$query .= implode(' ', $this->joins);
259264
}
265+
if (!empty($this->leftJoins)) {
266+
$query .= implode(' ', $this->leftJoins);
267+
}
260268
if (!empty($this->where)) {
261269
$query .= "\n WHERE " . implode(" AND ", $this->where);
262270
}
@@ -293,6 +301,14 @@ public function resetHaving()
293301
$this->having = [];
294302
}
295303

304+
/**
305+
*
306+
*/
307+
public function resetLeftJoins()
308+
{
309+
$this->leftJoins = [];
310+
}
311+
296312
/**
297313
* @param $limit
298314
* @param $offset

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Simple PDO Query Builder",
55
"keywords": ["pdo", "query builder"],
66
"license": "MIT",
7-
"version": "1.3.2",
7+
"version": "1.3.3",
88
"authors": [
99
{
1010
"name": "Vasily Sokolov",

0 commit comments

Comments
 (0)