feat: add Query Builder whereExists methods#10185
Open
memleakd wants to merge 1 commit intocodeigniter4:4.8from
Open
feat: add Query Builder whereExists methods#10185memleakd wants to merge 1 commit intocodeigniter4:4.8from
memleakd wants to merge 1 commit intocodeigniter4:4.8from
Conversation
- Add whereExists() and whereNotExists() condition helpers - Support Closure and BaseBuilder subqueries - Document usage and raw SQL limitations Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
310086a to
b7e16d1
Compare
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 adding
whereExists(),orWhereExists(),whereNotExists(), andorWhereNotExists()to the Query Builder.EXISTSandNOT EXISTSconditions are common in real applications for filtering records by related data, checking membership/authorization relationships, and expressing “does a matching row exist?” without turning the query into a join.This keeps the condition inside the Query Builder flow instead of requiring users to write the
EXISTS (...)clause manually. It also pairs naturally with the recently addedwhereColumn()support for correlated subqueries.The API follows the existing Query Builder subquery style used by methods like
whereIn(): it accepts a Closure orBaseBuilderinstance. Raw SQL strings are intentionally not accepted; users who need fully manual SQL can still usewhere().Changes
whereExists()andorWhereExists().whereNotExists()andorWhereNotExists().ORandNOT EXISTSvariants, grouped conditions, bind handling, invalid inputs, and the existing same-builder guard.Checklist: