prisma nested writes / updates not working
My prisma schema currently looks like this:
I want to make an API call which creates a topic specific to a subject. For example, if I specify that the subject is biology, it should make a new topic nested under biology. This is my current code which attempts that:
However when I try calling this API I get a 405 error, in addition to that I'm pretty sure the way I'm trying to do this is wrong as well. How would I be able to do this? Thanks
4 Replies
The idea is that on the website there should be a create topic button which I can click and create a topic for a specific subject
the subject name is not unique, so you can't use it with the "findUnique"
in order to fix that you should either change the function to "findFirst" if you're okay on having duplicated names, or add @unique on the name field on the prisma schema
you would see that the way you're running findUnique would be wrong if you didn't used the "as SubjectsWhereUniqueInput"
I managed to fix it but I ran into another issue
Here is my new api call:
and here is my clientside code
how can I change the names in " data: [{ name: "Topic 1" }, { name: "Topic 2"}]," to the names inputed in the input text box on the client side?
just read the "name" that you're sending on the post request through the body
also notice that with the current UI you're only getting 1 name at a time