Uh oh!
There was an error while loading. Please reload this page.
feat: add Query Builder whereExists methods - #10185
Conversation
310086a to
b7e16d1CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
paulbalandan
left a comment
There was a problem hiding this comment.
Please rebase against latest 4.8.
190d859 to
129fae7Comparepaulbalandan
commented
May 11, 2026
Sorry for the rector noise. It's being handled in #10181 |
michalsn
left a comment
There was a problem hiding this comment.
Should we add whereExists(), orWhereExists(), whereNotExists(), and orWhereNotExists() to the @method entries? https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/Model.php#L43
memleakd
commented
May 11, 2026
Yes, good point. Added the four |
paulbalandan
commented
May 14, 2026
A rebase then this can be merged. Thanks. |
- 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>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
c922eb2 to
47f3057Comparememleakd
commented
May 14, 2026
Done |
Uh oh!
There was an error while loading. Please reload this page.
memleakd
commented
May 14, 2026
Thank you @paulbalandan@michalsn |
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: