redwoodjs-com-archive icon indicating copy to clipboard operation
redwoodjs-com-archive copied to clipboard

Schema Relations docs needs updating (as of Prisma 2.11.0)

Open Tobbe opened this issue 4 years ago • 11 comments

Now that https://github.com/prisma/prisma/issues/2152 is closed, we need to update https://redwoodjs.com/docs/schema-relations, right? No relations workaround needed anymore, IIUC

Tobbe avatar Nov 25 '20 09:11 Tobbe

Yes, but I think we also need to update the scaffold generator to actually create a Text/Number field for the foreign ID! We should try to coordinate the changes if we can...

cannikin avatar Nov 25 '20 17:11 cannikin

seems like redwood is on prisma 2.12.1 now but afaict it doesn't appear with foreign key IDs still? (output pasted below). Is it possible to get working with prisma or do I need to still use the hack in the docs?

also possible my issue is related to using differing column vs table names

api | Unknown arg `ownerId` in data.ownerId for type AskCreateInput. Did you mean `owner`?
api | Unknown arg `companyId` in data.companyId for type AskCreateInput. Did you mean `company`?
api | Argument owner for data.owner is missing.
api | Argument company for data.company is missing.
api |
api | Note: Lines with + are required, lines with ? are optional.
...
api | data: {
api |     ownerId: ef7dd027-f9a8-4351-b76b-6aacbb8a88c5,
api |     ~~~~~~~
api |     companyId: dc7085fb-62e0-405c-bb0f-a4d33fa6bcae,
api |     ~~~~~~~~~
api | +   owner: {
api | +     create?: UserCreateWithoutAskInput,
api | +     connect?: UserWhereUniqueInput,
api | +     connectOrCreate?: UserCreateOrConnectWithoutAskInput
api | +   },
api | +   company: {
api | +     create?: CompanyCreateWithoutAskInput,
api | +     connect?: CompanyWhereUniqueInput,
api | +     connectOrCreate?: CompanyCreateOrConnectWithoutAskInput
api | +   },

wminshew avatar Jan 26 '21 00:01 wminshew

ah, I see now from the release notes I need to set a flag on the prisma client

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["uncheckedScalarInputs"]
}

wminshew avatar Jan 26 '21 01:01 wminshew

Yes, sorry for the delay, we're in the process of vetting 2.13.0+ so we can include that flag and the foreign key functionality by default. Unfortunately it is going to break a few things (like being able to use different databases in development and production) so we're working through those and getting them documented for release notes and docs for new users.

cannikin avatar Jan 26 '21 01:01 cannikin

all good :) Thank you for the quick response! (and as a follow up everything is working well so far since I added the flag)

wminshew avatar Jan 26 '21 01:01 wminshew

hm one thing I'm noticing is it doesn't seem to work for "many" relationships, just on the singular side (so out of luck for many to many relationships). Do you know if there are any workarounds for this today? I suppose I could augment the hack from the docs, but wondering if there's another option that might make more sense

wminshew avatar Jan 26 '21 01:01 wminshew

Hmmm...have you checked Prisma's issues? This sounds like a limitation on their side...

cannikin avatar Jan 27 '21 17:01 cannikin

Yeah good call I'll explore over there. I've fallen back to the ~old (not-unchecked) style in the meantime for that particular use case. Thanks!

wminshew avatar Jan 27 '21 17:01 wminshew

@wminshew FWIW --> Ryan from Prisma covered some of these topics at a Meetup back in September. Couldn't set the foreign key at that time, but you might find his examples helpful. See the video link at the topic as well as list of included topics on this page: https://community.redwoodjs.com/t/sept-11th-meetup-recap-recording-topics-and-links/1211

thedavidprice avatar Jan 27 '21 19:01 thedavidprice

thanks I'll check it out. Unfortunately encountered what I think is a bug in the meantime: https://github.com/prisma/prisma/issues/5294

might have to switch my whole code base back off unchecked unf

wminshew avatar Jan 27 '21 22:01 wminshew

Sounds good. But bummer about the potential bug 👎

thedavidprice avatar Jan 27 '21 22:01 thedavidprice