-
-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Labels
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.