fix: getCasts() to include casts() method for non-incrementing models #336
+97
−1
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.
Summary
The
getCasts()method inHasAttributeswas only calling$this->casts()for incrementing models. For non-incrementing models (those usingHasUuidsorHasUlids), only the$castsproperty was returned, ignoring thecasts()method entirely.The Bug
Impact
Any model using
HasUuidsorHasUlidsthat defines casts via thecasts()method (Laravel's modern approach) would have those casts ignored. This causes issues like:The Fix
Now the non-incrementing branch also merges both the property and method, matching the behavior of the incrementing branch.
Test Plan
HasAttributesTestwith 3 test cases:testGetCastsIncludesCastsMethodForIncrementingModels- existing behavior workstestGetCastsIncludesCastsMethodForNonIncrementingModels- UUID models get casts() methodtestGetCastsMergesPropertyAndMethodForNonIncrementingModels- both property and method are merged