Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit 8711d2a

Browse files
committed
Changed the second parameter of leftJoinRaw and joinRaw to string
1 parent a406340 commit 8711d2a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

docs/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ the `joinRaw` and `leftJoinRaw` method.
248248
```php
249249
$users = $this->select()
250250
->from('users AS u')
251-
->joinRaw('posts AS p', new RawExp('p.user_id=u.id AND u.enabled=1 OR p.published IS NULL'))
251+
->joinRaw('posts AS p', 'p.user_id=u.id AND u.enabled=1 OR p.published IS NULL')
252252
->execute()
253253
->fetchAll();
254254
```

src/Database/SelectQuery.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ public function leftJoin(string $table, string $leftField, string $comparison, $
222222
* Join with complex conditions.
223223
*
224224
* @param string $table Table name
225-
* @param RawExp $raw
225+
* @param string $conditions The ON conditions e.g. 'user.id = article.user_id'
226226
* @return self
227227
*/
228-
public function joinRaw(string $table, RawExp $raw): self
228+
public function joinRaw(string $table, string $conditions): self
229229
{
230-
$this->join[] = ['inner', $table, $raw, null, null, null];
230+
$this->join[] = ['inner', $table, new RawExp($conditions), null, null, null];
231231

232232
return $this;
233233
}
@@ -236,12 +236,12 @@ public function joinRaw(string $table, RawExp $raw): self
236236
* Left join with complex conditions.
237237
*
238238
* @param string $table Table name
239-
* @param RawExp $raw
239+
* @param string $conditions The ON conditions e.g. 'user.id = article.user_id'
240240
* @return self
241241
*/
242-
public function leftJoinRaw(string $table, RawExp $raw): self
242+
public function leftJoinRaw(string $table, string $conditions): self
243243
{
244-
$this->join[] = ['left', $table, $raw, null, null, null];
244+
$this->join[] = ['left', $table, new RawExp($conditions), null, null, null];
245245

246246
return $this;
247247
}

tests/SelectQueryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ public function testJoinRaw()
592592
$select = $this->select()
593593
->columns('id')
594594
->from('test')
595-
->joinRaw('users u', new RawExp('t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL'));
595+
->joinRaw('users u', 't2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL');
596596
$this->assertInstanceOf(PDOStatement::class, $select->prepare());
597597
$this->assertSame("SELECT `id` FROM `test` INNER JOIN `users` `u` ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL);", $select->build());
598598
}
@@ -611,7 +611,7 @@ public function testLeftJoinRaw()
611611
$select = $this->select()
612612
->columns('id')
613613
->from('test')
614-
->leftJoinRaw('users u', new RawExp('t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL'));
614+
->leftJoinRaw('users u', 't2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL');
615615
$this->assertInstanceOf(PDOStatement::class, $select->prepare());
616616
$this->assertSame("SELECT `id` FROM `test` LEFT JOIN `users` `u` ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c OR t2.b IS NULL);", $select->build());
617617
}

0 commit comments

Comments
 (0)