Fix populate() for array fields with ref on items#8324
Merged
Conversation
…rray RxDocument.populate() threw DOC6 for array fields when `ref` was defined on `items` instead of on the array field itself, even though createRxSchema accepts both patterns. Now populate() also checks items.ref as a fallback for array-type schema fields. https://claude.ai/code/session_012UknZ1m9tWSKkdi8nmWcqJ
The project uses individual files in orga/changelog/ instead of direct edits to CHANGELOG.md, to avoid merge conflicts across PRs. https://claude.ai/code/session_012UknZ1m9tWSKkdi8nmWcqJ
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.
This PR contains:
Describe the problem you have without this PR
RxDocument.populate()was throwing aDOC6error when called on array fields that have therefproperty defined on theitemsschema object instead of on the array field itself. However,createRxSchemaaccepts both patterns as valid, creating an inconsistency.For example, this schema pattern was not supported by
populate():Changes
Source Code
Modified
src/rx-document.tsto check forrefin two locations:itemsproperty if the field is an array (new behavior)This allows
populate()to work with both ref definition patterns that the schema validation already accepts.Tests
Added comprehensive unit test in
test/unit/population.test.tsthat:refdefined on arrayitemspopulate()correctly resolves the references_getter also works with this patternDocumentation
Updated
CHANGELOG.mdwith the fix description.Test Plan
Added unit tests that cover the fix. The test creates documents with array fields containing refs defined on items, calls
populate(), and verifies the references are correctly resolved to RxDocument instances.https://claude.ai/code/session_012UknZ1m9tWSKkdi8nmWcqJ