Fix lazy field handling in base class and OrFail templates#91
Merged
dereuromark merged 4 commits intomasterfrom Mar 23, 2026
Merged
Fix lazy field handling in base class and OrFail templates#91dereuromark merged 4 commits intomasterfrom
dereuromark merged 4 commits intomasterfrom
Conversation
- Fix base validate() to check _lazyData for required lazy fields - Fix base setDefaults() to not overwrite lazy field data - Fix setDefaults template to check _lazyData for lazy fields with defaults - Fix method_get_or_fail.twig to call getter (handles hydration) - Fix method_set_or_fail.twig to clear _lazyData for lazy fields - Fix method_with_or_fail.twig to clear _lazyData for lazy fields
Tests verify that generated code properly handles lazy fields: - setFromArrayFast uses array_key_exists - setDefaults checks _lazyData for lazy fields with defaults - validate checks _lazyData for required lazy fields - getOrFail calls getter (handles hydration) - setOrFail clears _lazyData - withOrFail clears _lazyData - getter uses array_key_exists for null detection
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #91 +/- ##
=========================================
Coverage 83.48% 83.48%
- Complexity 1388 1390 +2
=========================================
Files 40 40
Lines 3348 3348
=========================================
Hits 2795 2795
Misses 553 553 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The add/remove methods for lazy collections were clearing _lazyData before hydration, causing existing collection items to be lost. Fixed by calling the getter first (which handles hydration and clears _lazyData internally) before modifying the collection. Affected templates: - method_add.twig - method_remove.twig - method_with_added.twig - method_with_removed.twig Added tests to verify the fix and a lazy-specific benchmark.
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.
Summary
Comprehensive lazy field handling fixes discovered in deep dive.
Base class fixes (
Dto.php):validate()to check_lazyDatafor required lazy fieldssetDefaults()to not overwrite lazy field dataTemplate fixes:
setDefaultstemplate to check_lazyDatafor lazy fields with defaultsmethod_get_or_fail.twigto call getter (handles lazy hydration)method_set_or_fail.twigto clear_lazyDatafor lazy fieldsmethod_with_or_fail.twigto clear_lazyDatafor lazy fieldsmethod_add.twigto hydrate lazy collection before adding (prevents data loss)method_remove.twigto hydrate lazy collection before removingmethod_with_added.twigto hydrate lazy collection before addingmethod_with_removed.twigto hydrate lazy collection before removingTests:
Relates to #83