Skip to content

Fix populate() for array fields with ref on items#8324

Merged
pubkey merged 2 commits intomasterfrom
claude/fix-population-bug-j4gAi
Apr 11, 2026
Merged

Fix populate() for array fields with ref on items#8324
pubkey merged 2 commits intomasterfrom
claude/fix-population-bug-j4gAi

Conversation

@pubkey
Copy link
Copy Markdown
Owner

@pubkey pubkey commented Apr 10, 2026

This PR contains:

  • A BUGFIX
  • IMPROVED TESTS

Describe the problem you have without this PR

RxDocument.populate() was throwing a DOC6 error when called on array fields that have the ref property defined on the items schema object instead of on the array field itself. However, createRxSchema accepts both patterns as valid, creating an inconsistency.

For example, this schema pattern was not supported by populate():

friends: {
    type: 'array',
    items: {
        ref: 'human',
        type: 'string'
    }
}

Changes

Source Code

Modified src/rx-document.ts to check for ref in two locations:

  1. Directly on the schema object (existing behavior)
  2. On the items property 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.ts that:

  • Creates a schema with ref defined on array items
  • Inserts documents with array references
  • Verifies populate() correctly resolves the references
  • Verifies the pseudo-proxy _ getter also works with this pattern

Documentation

Updated CHANGELOG.md with 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

claude added 2 commits April 10, 2026 07:14
…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
@pubkey pubkey merged commit 32d2a69 into master Apr 11, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants