Skip to content

v1.1.2: "One-to-many (inversed)" not working as documented #345

Description

@heiwen

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions