model Product {
id Int @id@default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime
variant Variant[]
}
model Variant {
id Int @id@default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime
title String
product Product
}
Using Form generated by the scaffold, how do I edit and save ‘variant’ in ‘Post’ Model and edit ‘product’ in ‘Variant’
I am gettings errors at web and api side
a) not defined fields for product in Variant and not defined fields for variant in ‘Product’ in generated query
b) while submitting the data to the server, ID is a string when Int is expected errors from the remote graphql server
This might be new with Redwood’s move to Prisma 2.0 but I got the existing form scaffold working. It just needs some additional logic in the service methods.
Consider this schema,
model RepoMeasurement {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
repository Repository @relation(fields: [repositoryId], references: [id])
metric Metric @relation(fields: [metricId], references: [id])
value Int
repositoryId Int
metricId Int
}
When I use the scaffold it creates the following, which has no consideration of the @relation,
Because of that, Prisma complains about unknown fields repositoryId and metricId being passed in and necessary fields repository and metric being omitted. This simple change makes it work,
I assume this could be generated by the scaffolding system. I’d be willing to try with a head nod from maintainers. It wouldn’t handle the case in which the foreign row isn’t defined but that wouldn’t be much surprise because the generated form field takes an integer. It is surprising that even that connection doesn’t work.
I’d be willing to try with a head nod from maintainers.
^^ I want to fan this flame but need to provide a little background first! Back in April, we didn’t know yet where Prisma syntax and features for relations would settle. So we didn’t want to offer full generator support until that happened. (Or at least then have the discussion about the appropriate scope of generator support.) Originally the workaround from my forum topic above was going to live in api/lib/db.js, but this also felt like we’d potentially run into backward compatibility issues. (aside: then we talked about creating our own wrapper for the Prisma Client, which we would then import in db.js, which could possibly allow some magic but at least make it clear where the magic was coming from. So this is why we kept the db.js)
So where we are today is that relations are a confusing, sticky point for a lot of people. But there are a lot of types of relations that Prisma can handle (here’s the list).
To discuss:
Does Redwood Scaffold support generators and, if so, which types?
If not all types, how will Redwood handle the DX when a developer runs a Scaffold generators? (Currently it’s kind of a worst case false positive – generator ran successfully, CRUD is busted)
Given all that, what are your initial thoughts/reactions? I’m game to keep exploring, just say the word.