feat: add closure-based Query Builder join conditions#10186
Open
memleakd wants to merge 2 commits intocodeigniter4:4.8from
Open
feat: add closure-based Query Builder join conditions#10186memleakd wants to merge 2 commits intocodeigniter4:4.8from
memleakd wants to merge 2 commits intocodeigniter4:4.8from
Conversation
- Add JoinClause for protected JOIN ON column and value conditions - Support grouped and nested join conditions with Query Builder-style methods - Share join condition compilation with SQLSRV - Document the closure join API and add focused builder coverage Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR proposes a closure-based way to build Query Builder
JOIN ONclauses.Today, simple joins are easy:
But once a join needs bound values,
ORconditions, or groupedON (...)logic, users often have to fall back to longer raw SQL strings orRawSql. That works, but it gives up some of the safety and readability the Query Builder usually provides.This PR keeps the existing
join()API intact and adds a native option for those more complex join conditions:For grouped conditions:
This produces a protected, bound
JOIN ONclause without requiring users to manually write the whole condition as raw SQL.The closure receives a
JoinClauseobject with familiar Query Builder-style methods:on()/orOn()for column comparisonswhere()/orWhere()for bound value comparisonsgroupStart()/orGroupStart()/notGroupStart()/orNotGroupStart()/groupEnd()for grouped conditionsExisting string and
RawSqljoin conditions continue to work as before.RawSqlremains the explicit escape hatch for cases that do not fit this small join-condition API.Why
This helps real-world applications express safer and clearer joins, especially when joins include conditional matching, status filters, soft-delete checks, tenant constraints, or grouped
ORlogic inside theONclause.Instead of choosing between a simple protected join string and a fully raw condition, users get a CodeIgniter-native middle path that keeps identifiers protected and values bound.
Changes
CodeIgniter\Database\JoinClause.BaseBuilder::join().join()calls.Checklist: