Skip to content

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

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

wakqasahmed wants to merge 2 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 wakqasahmed left a comment

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.

Independent review found one reproducible alias-tracking issue with DBPrefix (inline below). Verified the affected JOIN compilation on PHP 8.2 in a disposable container. The Postgre and SQLSRV signature changes and raw-target bypass are consistent with the new API, and the 4.8 upgrade notes cover subclass compatibility. Remaining validation gap: no live PostgreSQL or SQL Server execution performed during this review.

Comment thread system/Database/BaseBuilder.php Outdated
protected function trackAliases($table)
{
if ($table instanceof RawSql) {
if (preg_match('/\)\s+(?:AS\s+)?([a-z_][a-z0-9_]*)\s*$/i', (string) $table, $matches)) {

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.

[P2] Track aliases for other valid raw JOIN targets

The new matcher only recognizes an unquoted alias immediately following ). With DBPrefix = "ci_", join(new RawSql("posts recent"), "recent.user_id = users.id") compiles to JOIN posts recent ON "ci_recent"."user_id" = "ci_users"."id", referring to an alias that does not exist. The same failure occurs for a protected subquery alias such as new RawSql('(SELECT user_id FROM posts) AS "recent"'). Both were reproduced on PHP 8.2; the existing unquoted subquery case passes. Please recognize terminal aliases for ordinary raw table expressions and quoted subquery aliases, and add prefix regressions for these cases so the string condition retains the actual alias.

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.

Fixed in 9d63234. Raw JOIN alias tracking now recognizes ordinary table aliases and quoted subquery aliases, with DBPrefix regressions for both cases. JoinTest passes (16 tests); PHP 8.2 syntax and file-scoped style checks pass.

@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?

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.

1 participant