Skip to content

Commit b720c2c

Browse files
author
ndm2
committed
Further join() docblock improvements
Add example for array usage, simplify docblocks, fix yoda conditions and typos
1 parent 4150f29 commit b720c2c

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

src/Database/Query.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public function from($tables = [], $overwrite = false) {
388388
}
389389

390390
/**
391-
* Adds a single or multiple tables to be used as JOIN clauses this query.
391+
* Adds a single or multiple tables to be used as JOIN clauses to this query.
392392
* Tables can be passed as an array of strings, an array describing the
393393
* join parts, an array with multiple join descriptions, or a single string.
394394
*
@@ -426,18 +426,18 @@ public function from($tables = [], $overwrite = false) {
426426
* 'p' => [
427427
* 'table' => 'publishers',
428428
* 'type' => 'INNER',
429-
* 'conditions' => 'b.publisher_id = p.id AND p.name = "Cake Software Foundation"'
429+
* 'conditions' => 'p.id = b.publisher_id AND p.name = "Cake Software Foundation"'
430430
* ]
431431
* ]);
432432
* // LEFT JOIN authors a ON a.id = b.author_id
433-
* // INNER JOIN publishers p ON b.publisher_id = p.id AND p.name = "Cake Software Foundation"
433+
* // INNER JOIN publishers p ON p.id = b.publisher_id AND p.name = "Cake Software Foundation"
434434
* }}}
435435
*
436436
* ### Using conditions and types
437437
*
438438
* Conditions can be expressed, as in the examples above, using a string for comparing
439439
* columns, or string with already quoted literal values. Additionally it is
440-
* possible to using conditions expressed in arrays or expression objects.
440+
* possible to use conditions expressed in arrays or expression objects.
441441
*
442442
* When using arrays for expressing conditions, it is often desirable to convert
443443
* the literal values to the correct database representation. This is achieved
@@ -513,19 +513,33 @@ public function join($tables = null, $types = [], $overwrite = false) {
513513
/**
514514
* Adds a single LEFT JOIN clause to the query.
515515
*
516+
* This is a shorthand method for building joins via `join()`.
517+
*
518+
* The table name can be passed as a string, or as an array in case it needs to
519+
* be aliased:
520+
*
516521
* {{{
517-
* // LEFT JOIN authors ON posts.author_id = authors.id
518-
* $query->leftJoin('authors', ['posts.author_id = authors.id']);
522+
* // LEFT JOIN authors ON authors.id = posts.author_id
523+
* $query->leftJoin('authors', 'authors.id = posts.author_id');
524+
*
525+
* // LEFT JOIN authors a ON a.id = posts.author_id
526+
* $query->leftJoin(['a' => 'authors'], 'a.id = posts.author_id');
519527
* }}}
520528
*
521-
* You can pass an array in the first parameter if you need to alias
522-
* the table for the join:
529+
* Conditions can be passed as strings, arrays, or expression objects. When
530+
* using arrays it is possible to combine them with the `$types` parameter
531+
* in order to define how to convert the values:
523532
*
524533
* {{{
525-
* // LEFT JOIN authors a ON posts.author_id = a.id
526-
* $query->leftJoin(['a' => 'authors'], ['posts.author_id = a.id']);
534+
* $query->leftJoin(['a' => 'articles'], [
535+
* 'a.posted >=' => new DateTime('-3 days'),
536+
* 'a.published' => true,
537+
* 'a.author_id = authors.id'
538+
* ], ['a.posted' => 'datetime', 'a.published' => 'boolean']);
527539
* }}}
528540
*
541+
* See `join()` for further details on conditions and types.
542+
*
529543
* @param string|array $table The table to join with
530544
* @param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
531545
* to use for joining.
@@ -540,18 +554,10 @@ public function leftJoin($table, $conditions = [], $types = []) {
540554
/**
541555
* Adds a single RIGHT JOIN clause to the query.
542556
*
543-
* {{{
544-
* // RIGHT JOIN authors ON posts.author_id = authors.id
545-
* $query->rightJoin('authors', ['posts.author_id = authors.id']);
546-
* }}}
547-
*
548-
* You can pass an array in the first parameter if you need to alias
549-
* the table for the join:
557+
* This is a shorthand method for building joins via `join()`.
550558
*
551-
* {{{
552-
* // RIGHT JOIN authors a ON posts.author_id = a.id
553-
* $query->righJoin(['a' => 'authors'], ['posts.author_id = a.id']);
554-
* }}}
559+
* The arguments of this method are identical to the `leftJoin()` shorthand, please refer
560+
* to that methods description for further details.
555561
*
556562
* @param string|array $table The table to join with
557563
* @param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
@@ -567,18 +573,10 @@ public function rightJoin($table, $conditions = [], $types = []) {
567573
/**
568574
* Adds a single INNER JOIN clause to the query.
569575
*
570-
* {{{
571-
* // INNER JOIN authors ON posts.author_id = authors.id
572-
* $query->innerJoin('authors', ['posts.author_id = authors.id']);
573-
* }}}
576+
* This is a shorthand method for building joins via `join()`.
574577
*
575-
* You can pass an array in the first parameter if you need to alias
576-
* the table for the join:
577-
*
578-
* {{{
579-
* // INNER JOIN authors a ON posts.author_id = a.id
580-
* $query->innerJoin(['a' => 'authors'], ['posts.author_id = a.id']);
581-
* }}}
578+
* The arguments of this method are identical to the `leftJoin()` shorthand, please refer
579+
* to that methods description for further details.
582580
*
583581
* @param string|array $table The table to join with
584582
* @param string|array|\Cake\Database\ExpressionInterface $conditions The conditions

0 commit comments

Comments
 (0)