Bug description
You are unable to create a new record by using the foreign key to another table. For example if a Post has a userId column, you cannot just set the userId and save the record.
How to reproduce
Given the schema shown below, create a User and note its ID. Let's say it is 1 in this case. Now try to create a post:
db.post.create({ data: { title: 'My post', body: 'Lorem ipsum...', userId: 1 } })
Error:
Invalid `prisma.post.create()` invocation:
{
data: {
title: 'First post',
body: 'Body goes here',
userId: 1,
~~~~~~
+ user: {
+ create?: UserCreateWithoutPostsInput,
+ connect?: UserWhereUniqueInput
+ }
}
}
Unknown arg `userId` in data.userId for type PostCreateInput. Did you mean `user`?
Argument user for data.user is missing.
Expected behavior
The Post record is created and userId is set to 1.
Prisma information
// schema.prisma
datasource DS {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String @unique
body String
user User @relation(fields: [userId], references: [id])
userId Int
}
Environment & setup
rob$ yarn prisma -v
yarn run v1.22.4
$ /Users/rob/Sites/redwoodjs/abbott/node_modules/.bin/prisma -v
@prisma/cli : 2.0.0-beta.1
Current platform : darwin
Query Engine : prisma 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/rob/Sites/redwoodjs/abbott/node_modules/@prisma/cli/query-engine-darwin)
Migration Engine : migration-engine-cli 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/rob/Sites/redwoodjs/abbott/node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/rob/Sites/redwoodjs/abbott/node_modules/@prisma/cli/introspection-engine-darwin)
Why this is important
With RedwoodJS we have generators that create simple CRUD pages for working the data in your database. In this case we would create a "Post" form to let you create new ones. To associate the new post to a user we provide a userId input. Ideally the user just enters the ID of the user and they're done:

Unfortunately this behavior breaks that completely. :( We would need a lot of code to work around this (perform an extra database query to look up the user and then include that user using the connect syntax, I guess?). This can all be avoided by just letting users set all the fields in the database table, which most would expect to be able to do.
Bug description
You are unable to create a new record by using the foreign key to another table. For example if a
Posthas auserIdcolumn, you cannot just set theuserIdand save the record.How to reproduce
Given the schema shown below, create a
Userand note its ID. Let's say it is1in this case. Now try to create a post:Error:
Expected behavior
The
Postrecord is created anduserIdis set to1.Prisma information
Environment & setup
Why this is important
With RedwoodJS we have generators that create simple CRUD pages for working the data in your database. In this case we would create a "Post" form to let you create new ones. To associate the new post to a user we provide a
userIdinput. Ideally the user just enters the ID of the user and they're done:Unfortunately this behavior breaks that completely. :( We would need a lot of code to work around this (perform an extra database query to look up the user and then include that user using the
connectsyntax, I guess?). This can all be avoided by just letting users set all the fields in the database table, which most would expect to be able to do.