Skip to content

Conversation

@davebarnwell
Copy link
Owner

Summary

  • return null for single-record fetches when no rows exist
  • handle no-op inserts/updates safely and reset caches on reconnect
  • add tests for missing fetches and empty insert/update behavior

Testing

  • MODEL_ORM_TEST_DSN="mysql:host=127.0.0.1;port=3306" MODEL_ORM_TEST_USER="root" MODEL_ORM_TEST_PASS="" vendor/bin/phpunit -c phpunit.xml.dist
  • vendor/bin/phpstan analyse -c phpstan.neon

Copilot AI review requested due to automatic review settings January 30, 2026 22:25
@davebarnwell davebarnwell merged commit a28f3ca into master Jan 30, 2026
8 checks passed
@davebarnwell davebarnwell deleted the fix-model-edge-cases-and-tests branch January 30, 2026 22:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens the Model ORM’s behavior around “no row” edge cases and no-op writes, and adds tests to lock in the new semantics. It also ensures DB-level caches are reset correctly on reconnect.

Changes:

  • Make single-record fetch APIs (getById, first, last, fetchOneWhere) return null when no rows are found, and adjust fetchWhere accordingly.
  • Handle inserts with no dirty fields by issuing DEFAULT VALUES / () VALUES () SQL depending on the driver, and make update() return false instead of running a no-op UPDATE when there are no dirty fields.
  • Reset identifier-quote, statement cache, and table column cache on connectDb(), and add PHPUnit tests covering missing fetches and empty insert/update behavior for Category.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Model/Model.php Adjusts connection setup to reset internal caches; updates fetch helpers to return null for missing records; safely handles insert/update when there are no dirty fields; updates return types/docblocks to match new behavior.
tests/Model/CategoryTest.php Extends category integration tests to assert non-null result from getById, verify fetchOneWhere returns null when no row exists, confirm inserts with no dirty fields still create a row and set id, and assert update(false) returns false when there are no dirty fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants