v1.1.2: "One-to-many (inversed)" not working as documented
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 67
- Avg merge
- 9m
- Merged PRs (30d)
- 5
Description
I'm trying to reproduce the following documented example:
import { Collection } from "@msw/data"
import z from "zod/v4"
const postSchema = z.object({
get comments() {
return z.array(commentSchema)
},
})
const commentSchema = z.object({
text: z.string(),
get post() {
return postSchema
},
})
const posts = new Collection({ schema: postSchema })
const comments = new Collection({ schema: commentSchema })
posts.defineRelations(({ many }) => ({
comments: many(comments),
}))
comments.defineRelations(({ one }) => ({
post: one(posts),
}))
await posts.create({
comments: [await comments.create({ text: 'First!' })],
})
const comment = comments.findFirst((q) => q.where({ text: 'First!' }))
comments.post // { comments: [{ text: 'First', post: Circular }] }
It fails with the error message:
error: Failed to create a new record with initial values: does not match the schema. Please see the schema validation errors above.
I'm using Bun 1.2.0, msw 2.12.2, msw/data 1.1.2 and zod 4.1.12.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the documented inverse one-to-many example from the issue with Bun, TypeScript, msw/data 1.1.2, and zod 4.1.12. Inspect the schema-validation failure during creation and compare the observed result with the documented circular relation; done means the example creates successfully and exposes the inverse relation as documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, typescript
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100