You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e0aa3ed
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: tests/system/Database/Builder/JoinTest.php
+74Lines changed: 74 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,68 @@ public function testJoinRawSql(): void
121
121
$this->assertSame($expectedSQL, $output);
122
122
}
123
123
124
+
publicfunctiontestJoinRawSqlTable(): void
125
+
{
126
+
$builder = newBaseBuilder('users', $this->db);
127
+
128
+
$builder->join(
129
+
newRawSql('(SELECT user_id, MAX(created_at) AS latest FROM posts GROUP BY user_id) recent'),
130
+
'recent.user_id = users.id',
131
+
'LEFT',
132
+
);
133
+
134
+
$expectedSQL = 'SELECT * FROM "users" LEFT JOIN (SELECT user_id, MAX(created_at) AS latest FROM posts GROUP BY user_id) recent ON "recent"."user_id" = "users"."id"';
Copy file name to clipboardExpand all lines: user_guide_src/source/changelogs/v4.8.0.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,7 @@ update your implementations to include the new methods or method changes to ensu
77
77
Method Signature Changes
78
78
========================
79
79
80
+
- **Database:** ``BaseBuilder::join()`` and ``BaseBuilder::compileJoinTable()`` now accept ``RawSql|string`` for the table argument. Custom builders overriding either method must accept both types. See :doc:`../installation/upgrade_480`.
80
81
- **CLI:** The ``Console::run()`` method now accepts an optional ``array $tokens`` parameter. This allows you to pass an array of command tokens directly to the console runner, which is useful for testing or programmatically running commands. If not provided, it will default to using the global ``$argv``.
81
82
- **CodeIgniter:** The deprecated parameters in methods have been removed:
82
83
- ``CodeIgniter\CodeIgniter::handleRequest()`` no longer accepts the deprecated ``$cacheConfig`` and ``$returnResponse`` parameters.
@@ -292,6 +293,7 @@ Database
292
293
Query Builder
293
294
-------------
294
295
296
+
- ``BaseBuilder::join()`` now accepts ``RawSql`` as the table argument, allowing raw JOIN targets such as subqueries. See :ref:`query-builder-join-rawsql`.
295
297
- Added ``exists()`` and ``doesntExist()`` to Query Builder to check whether the current Query Builder query would return at least one row. See :ref:`query-builder-exists`.
296
298
- Added ``explain()`` to Query Builder to run execution-plan queries for the current ``SELECT`` query. See :ref:`query-builder-explain`.
297
299
- Added ``havingBetween()``, ``orHavingBetween()``, ``havingNotBetween()``, and ``orHavingNotBetween()`` to Query Builder. See :ref:`query-builder-having-between`.
Copy file name to clipboardExpand all lines: user_guide_src/source/database/query_builder.rst
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -301,6 +301,11 @@ Since v4.2.0, ``$builder->join()`` accepts a ``CodeIgniter\Database\RawSql`` ins
301
301
302
302
.. literalinclude:: query_builder/102.php
303
303
304
+
Since v4.8.0, the table can also be a ``RawSql`` instance. For example, you
305
+
can join a subquery:
306
+
307
+
.. literalinclude:: query_builder/134.php
308
+
304
309
.. warning:: When you use ``RawSql``, you MUST escape the values and protect the identifiers manually. Failure to do so could result in SQL injections.
0 commit comments