data
data copied to clipboard
Creating record with deeper nested relation fails schema validation
The following code fails to create a record:
const contactSchema = z.object({ email: z.string() })
const userSchema = z.object({ id: z.number(), contact: contactSchema })
const postSchema = z.object({
title: z.string(),
author: userSchema,
})
const contacts = new Collection({ schema: contactSchema })
const users = new Collection({ schema: userSchema })
const posts = new Collection({ schema: postSchema })
users.defineRelations(({ one }) => ({
contact: one(contacts),
}))
posts.defineRelations(({ one }) => ({
author: one(users),
}))
const contact = await contacts.create({ email: '[email protected]' })
const user = await users.create({ id: 1, contact })
const post = await posts.create({ title: 'First', author: user })
I receive the following validation error from this code:
[
{
expected: 'object',
code: 'invalid_type',
path: [ 'author', 'contact' ],
message: 'Invalid input: expected object, received undefined'
}
]
Is this expected or am I doing something wrong?