Fix associative collection key extraction for pre-instantiated DTO objects#93
Merged
dereuromark merged 4 commits intomasterfrom Mar 23, 2026
Merged
Conversation
- XmlEngine: Throw exception for field definitions missing "name" attribute instead of silently skipping them - All engines: Use consistent is_string() check for shorthand field notation - All engines: Add validation error for invalid field types (not string or array) This makes debugging config issues easier and ensures consistent behavior across XML, YAML, Neon, and PHP engines.
…jects When passing pre-instantiated DTO objects to an associative collection with a key field, the keys were not being extracted from the DTOs - falling back to numeric indices instead. Changes: - Add extractKeyFromObject() helper method to extract keys from objects via getter methods, toArray(), or public properties - Fix createCollection() and createArrayCollection() to use existing DTO objects directly when they match the expected type (instead of creating empty DTOs) - Fix addValueToCollection() and addValueToArrayCollection() to extract keys from object elements - Update optimizations.twig template to use extractKeyFromObject() for generated setFromArrayFast() code - Add tests for associative collections with pre-instantiated DTO objects
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #93 +/- ##
============================================
- Coverage 83.48% 82.64% -0.85%
- Complexity 1390 1404 +14
============================================
Files 40 40
Lines 3348 3399 +51
============================================
+ Hits 2795 2809 +14
- Misses 553 590 +37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
When passing pre-instantiated DTO objects to an associative collection with a
keyfield, the keys were not being extracted from the DTOs - falling back to numeric indices instead.Before: Passing
[new ItemDto(['id' => 10]), new ItemDto(['id' => 20])]to anassociative="true" key="id"collection resulted in keys[0, 1]After: Keys are correctly extracted as
[10, 20]Changes
extractKeyFromObject()helper method to extract keys from objects via getter methods,toArray(), or public propertiescreateCollection()andcreateArrayCollection()to use existing DTO objects directly when they match the expected type (instead of creating empty DTOs)addValueToCollection()andaddValueToArrayCollection()to extract keys from object elementsoptimizations.twigtemplate to useextractKeyFromObject()for generatedsetFromArrayFast()code