Skip to content

feat: Allow RawSql JOIN tables (#9070) - #10571

Open
wakqasahmed wants to merge 4 commits into
codeigniter4:4.8from
wakqasahmed:feature/issue-9070-rawsql-join-table
Open

wakqasahmed wants to merge 4 commits into
codeigniter4:4.8from
wakqasahmed:feature/issue-9070-rawsql-join-table

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Description

  • Accept RawSql as the JOIN table, including in the Postgre and SQLSRV builders.
  • Register a trailing subquery alias so ON conditions work with database prefixes.
  • Document the new argument type and the signature change for custom builders.

The new base test failed with the original TypeError before the change. The local PHP image has no coverage driver, so coverage is left to CI.

Closes #9070.

Test plan:

  • JoinTest.php (14 tests)
  • PHP 8.2 syntax checks for the three changed production files
  • File-scoped Rector dry run

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage (coverage measurement pending CI)
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the 4.8 PRs that target the `4.8` branch. label Sep 19, 2026
wakqasahmed

This comment was marked as outdated.

@wakqasahmed

Copy link
Copy Markdown
Contributor Author

The updated JOIN regressions pass locally (16 tests), and the review fix is in 9d63234. The Oracle CI job failed in the randomized AutoReview test FrameworkCodeTest::testDeprecationsAreProperlyVersioned() because app/Transformers is absent; the failure does not exercise JOIN code. GitHub denied my rerun request with 403 (upstream admin rights required). Could a maintainer rerun the failed job?

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good. But please update the join signature in Model.php.

Comment on lines +307 to +315
.. code-block:: php

use CodeIgniter\Database\RawSql;

$builder->join(
new RawSql('(SELECT user_id, MAX(created_at) AS latest FROM posts GROUP BY user_id) recent'),
'recent.user_id = users.id',
'LEFT'
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use .. literalinclude:: instead - just like it's done in line 302.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated the join signature in Model.php and moved the example to query_builder/134.php with literalinclude.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants