Skip to content

Commit f3ef499

Browse files
committed
docs: update Model join signature and use literalinclude (#9070)
1 parent 41970be commit f3ef499

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎system/Model.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* @method $this havingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
6363
* @method $this havingNotBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
6464
* @method $this havingNotIn(?string $key = null, $values = null, ?bool $escape = null)
65-
* @method $this join(string $table, string $cond, string $type = '', ?bool $escape = null)
65+
* @method $this join(RawSql|string $table, RawSql|string $cond, string $type = '', ?bool $escape = null)
6666
* @method $this like($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
6767
* @method $this likeAny(list<RawSql|string> $fields, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
6868
* @method $this limit(?int $value = null, ?int $offset = 0)

‎user_guide_src/source/database/query_builder.rst‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,7 @@ Since v4.2.0, ``$builder->join()`` accepts a ``CodeIgniter\Database\RawSql`` ins
304304
Since v4.8.0, the table can also be a ``RawSql`` instance. For example, you
305305
can join a subquery:
306306

307-
.. code-block:: php
308-
309-
use CodeIgniter\Database\RawSql;
310-
311-
$builder->join(
312-
new RawSql('(SELECT user_id, MAX(created_at) AS latest FROM posts GROUP BY user_id) recent'),
313-
'recent.user_id = users.id',
314-
'LEFT'
315-
);
307+
.. literalinclude:: query_builder/134.php
316308

317309
.. warning:: When you use ``RawSql``, you MUST escape the values and protect the identifiers manually. Failure to do so could result in SQL injections.
318310

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use CodeIgniter\Database\RawSql;
4+
5+
$builder->join(
6+
new RawSql('(SELECT user_id, MAX(created_at) AS latest FROM posts GROUP BY user_id) recent'),
7+
'recent.user_id = users.id',
8+
'LEFT',
9+
);

0 commit comments

Comments
 (0)