@@ -273,9 +273,24 @@ public function orderBy($sort, $dir = 'desc') { return $this->sortBy($sort, $dir
273
273
* @param string $table Name of table to select from
274
274
* @return self
275
275
*/
276
- public function join ($ table )
277
- {
278
- $ this ->joins [] = ['table ' => $ table , 'where ' => [], 'on ' => []];
276
+ public function join ($ table , $ rawtype = null )
277
+ {
278
+ $ type = 'JOIN ' ;
279
+ if ($ rawtype ) switch (strtolower ($ rawtype )) {
280
+ case 'left ' :
281
+ $ type = 'LEFT JOIN ' ;
282
+ break ;
283
+ case 'left outer ' :
284
+ $ type = 'LEFT OUTER JOIN ' ;
285
+ break ;
286
+ case 'cross ' :
287
+ $ type = 'CROSS JOIN ' ;
288
+ break ;
289
+ default :
290
+ throw new Exception \Query ('Unknown Join Type ' );
291
+ }
292
+
293
+ $ this ->joins [] = ['table ' => $ table , 'type ' => $ type , 'where ' => [], 'on ' => []];
279
294
280
295
return $ this ;
281
296
}
@@ -287,9 +302,24 @@ public function join($table)
287
302
* @param string $alias Alias for the derived table
288
303
* @return self
289
304
*/
290
- public function joinSubquery ($ subquery , $ alias )
291
- {
292
- $ this ->joins [] = ['table ' => null , 'subquery ' => $ subquery , 'alias ' => $ alias , 'where ' => [], 'on ' => []];
305
+ public function joinSubquery ($ subquery , $ alias , $ rawtype = null )
306
+ {
307
+ $ type = 'JOIN ' ;
308
+ if ($ rawtype ) switch (strtolower ($ rawtype )) {
309
+ case 'left ' :
310
+ $ type = 'LEFT JOIN ' ;
311
+ break ;
312
+ case 'left outer ' :
313
+ $ type = 'LEFT OUTER JOIN ' ;
314
+ break ;
315
+ case 'cross ' :
316
+ $ type = 'CROSS JOIN ' ;
317
+ break ;
318
+ default :
319
+ throw new Exception \Query ('Unknown Join Type ' );
320
+ }
321
+
322
+ $ this ->joins [] = ['table ' => null , 'subquery ' => $ subquery , 'type ' => $ type , 'alias ' => $ alias , 'where ' => [], 'on ' => []];
293
323
return $ this ;
294
324
}
295
325
@@ -410,6 +440,12 @@ public function resolve()
410
440
411
441
public function resolveTable ()
412
442
{
443
+ if ($ this ->table instanceof QueryBuilder)
444
+ {
445
+ list ($ sql , $ subdata ) = $ this ->table ->resolve ();
446
+ $ this ->data = array_merge ($ this ->data , $ subdata );
447
+ return '( ' . $ this ->table ->resolve . ') AS subquery ' ;
448
+ }
413
449
return $ this ->escapeTable ($ this ->table );
414
450
}
415
451
@@ -423,15 +459,15 @@ public function resolveJoins()
423
459
{
424
460
if ($ join ['table ' ]) {
425
461
$ clauses = [];
426
- $ joinstring .= ' JOIN ' . $ this ->escapeTable ($ join ['table ' ]);
462
+ $ joinstring .= " { $ join [ ' type ' ]} " . $ this ->escapeTable ($ join ['table ' ]);
427
463
} elseif ($ join ['subquery ' ]) {
428
464
$ sql = $ join ['subquery ' ];
429
465
if ($ sql instanceof QueryBuilder) {
430
466
list ($ sql , $ subdata ) = $ join ['subquery ' ]->resolve ();
431
467
$ this ->data = array_merge ($ this ->data , $ subdata );
432
468
}
433
469
434
- $ joinstring .= " JOIN ( $ sql) as {$ join ['alias ' ]}" ;
470
+ $ joinstring .= " { $ join [ ' type ' ]} ( $ sql) as {$ join ['alias ' ]}" ;
435
471
}
436
472
437
473
if ($ join ['where ' ])
0 commit comments