Is it possible to have complex relational criteria...
# orm-help
i
Is it possible to have complex relational criteria in a
prisma.create
? I'm looking for the equivalent of:
Copy code
INSERT INTO membership(orgId, email, role)
SELECT orgId, @email as email, @role as role
FROM membership
WHERE orgId = @orgId
  AND userId = @userId
  AND (role = 'OWNER' OR (role = 'ADMIN' AND @role = 'USER'));
so you'd call it setting the
userId
to the current user taking the action, and this would assert that it would only create if the user has permission to add new users at the requested role (I know I can do
prisma.findUnique
to get the membership role of the current user, and then do it in javascript, but i try to avoid TOCTOU as a general practice.)
n
Hey Isaac 👋 Were you able to sort this out or are you still facing any issues?
i
@Nurul I was able to do this with a manual transaction in my case, yes. Not quite as slick/safe as just having the db perform the data validation in the scope of a single query, but it gets the job done.
🙌 1