Skip to content

feat: add Model::firstOrInsert() with failure handling#10012

Merged
michalsn merged 5 commits intocodeigniter4:4.8from
michalsn:feat/first-or-insert
Mar 2, 2026
Merged

feat: add Model::firstOrInsert() with failure handling#10012
michalsn merged 5 commits intocodeigniter4:4.8from
michalsn:feat/first-or-insert

Conversation

@michalsn
Copy link
Member

Description
This PR adds Model::firstOrInsert(), which finds the first row matching the given $attributes, or inserts a new row using the merged result of $attributes and $values. Both parameters accept an array, stdClass, or an Entity.

Closes #5163

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

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.8 PRs that target the `4.8` branch. labels Feb 27, 2026
@michalsn michalsn merged commit c82e68e into codeigniter4:4.8 Mar 2, 2026
50 checks passed
@michalsn
Copy link
Member Author

michalsn commented Mar 2, 2026

Thank you for the reviews!

@michalsn michalsn deleted the feat/first-or-insert branch March 2, 2026 12:37
JulianAtkins pushed a commit to JulianAtkins/CodeIgniter4 that referenced this pull request Mar 19, 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. enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants