Repository navigation
[#17689] - read back the generated id when the identity is 0 on adapters without sequences - #795
Merged
Merged
Conversation
…ers without sequences Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you @nadorator |
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.
Hello!
In raising this pull request, I confirm the following:
Small description of change:
Port of phalcon/cphalcon#17690.
Model::doLowInsert()reuses any non-empty identity value instead of callinglastInsertId()(fix for #16436). On MySQL,0is not an explicit id: MySQL replaces it with the next auto-increment value, so a model whose identity property is0keeps0aftersave()/create().The value on the model is now reused on adapters with sequences (as before) and for any explicit non-zero value. Only
0on adapters without sequences goes throughlastInsertId(), which returns the stored id (the generated one on MySQL,0on SQLite). The PostgreSQL behaviour from #16436 is unchanged.supportSequences()is now called once and stored in$useSequences.Tests (
tests/database/Mvc/Model/CreateTest.php), same as in cphalcon:testMvcModelCreateWithZeroIdentityMysql(data sets0and'0'): the model gets the id stored in the table.testMvcModelCreateWithZeroIdentitySqlite(data sets0and'0'):0is stored as given and read back as the string'0'.testMvcModelCreateWithExplicitIdMysqlSqlite: an explicit77is kept as int77.Checked locally with PHP 8.2.35:
CreateTestsqlite OK (5 tests, 18 assertions), mysql/MariaDB 10.6 OK (5 tests, 20 assertions); phpcs and phpstan pass on the changed files.Thanks
🤖 Generated with Claude Code