Skip to content

feat: add Query Builder likeAny helpers#10261

Merged
michalsn merged 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-like-any
Jun 11, 2026
Merged

feat: add Query Builder likeAny helpers#10261
michalsn merged 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-like-any

Conversation

@memleakd

Copy link
Copy Markdown
Contributor

Description

This PR proposes adding likeAny() and orLikeAny() to Query Builder.

The goal is to make a very common search pattern easier to write: search one value across a few columns, while keeping those LIKE conditions grouped safely.

$builder->where('active', 1)->likeAny(['title', 'body', 'summary'], $search);

Instead of writing the group manually, this produces the expected shape:

WHERE active = 1
AND (
    title LIKE '%term%'
    OR body LIKE '%term%'
    OR summary LIKE '%term%'
)

This keeps the existing like() behavior unchanged. Passing an associative array to like() still creates multiple LIKE clauses joined with AND; likeAny() is only for the "same value across any of these fields" case.

Internally this reuses the existing LIKE handling, so binds, escaping, wildcard placement, RawSql, and case-insensitive search behave the same way as like().

Tests cover grouped SQL generation, binds, invalid field lists, RawSql, case-insensitive search, and live database behavior.

Checklist:

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

- add likeAny() and orLikeAny() for grouped OR LIKE searches
- reuse existing LIKE handling for binds, escaping, RawSql, and insensitive search
- document usage and add builder/live coverage

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 31, 2026
Comment thread system/Database/BaseBuilder.php
@michalsn michalsn merged commit 944b328 into codeigniter4:4.8 Jun 11, 2026
57 checks passed
@michalsn

Copy link
Copy Markdown
Member

Thank you @memleakd

@memleakd memleakd deleted the feat/query-builder-like-any branch June 11, 2026 08:55
@paulbalandan paulbalandan added the new feature PRs for new features label Jul 8, 2026
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. new feature PRs for new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants