null to falsy value detection in syncDirtyFromProperties - #39
Merged
Merged
Conversation
Contributor
|
makes sense to me! Thanks again! |
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.
yep... I'm back again. 🤷♂️
ActiveRecord.php:459
syncDirtyFromProperties()compared stored vs current property values with!=. In PHP's loose comparison,nullequals0.0,0,'', andfalse. So when a property was set to0.0over a NULL column,0.0 != nullwas false, the property was never added to$dirty, andupdate()silently saved nothing. The reported case was writing0.0over NULL.The fix changes line 459 from != to
!==.I traced the code to make sure this does not cause false "changed" flags: on a normal find-then-update,
$dataand the property hold the same value and type, so!==only registers genuine changes and unchanged columns are not rewritten. ThecopyFrom()/dirty()path that could introduce mixed types is already skipped by the existing dirty-key guard. The loose-vs-strict operators only behave differently in the null-versus-falsy case, which is precisely the bug this fixes.Tests:
testUpdatePersistsZeroFloatOverNullandtestSyncDetectsFloatZeroChangeFromNullreproduce the bug: they fail with!=, pass with!==.testSyncDoesNotDirtyUnchangedTypedPropertiesproves re-assigning identical values leaves the dirty set empty, so no needless UPDATEs.Fixture change:
TypedUsergains a nullablecreditsfloat property, and the test schema gains acredits REALcolumn.Compatibility:
===/!==), so this change aligns with the project's stated standard.Verification: full suite (230 tests) green, coverage at 100%,
php -land PHPCS clean.