Replies: 2 comments 2 replies
-
I am going to try to do the creation within a transaction. So I create without permissions and check the results, if they have the permission. If not, I am going to throw an error which should rollback changes of the transaction. Only issue is, that prisma does not support it well in client extensions :/ |
Beta Was this translation helpful? Give feedback.
-
Create operation is different. You can’t check it with db query (though your idea with transaction is quite creative 👍 ) In my experience, I create record in memory and check whether it’s possible to create it in runtime before sending actual query to db |
Beta Was this translation helpful? Give feedback.
-
Hi @stalniy ,
My prisma-extension-casl package is doing well so far, but I am running into an issue, when I try to create entries with prisma.
like
client.user.create({ data: { id: 0 } })
or also forconnectOrCreate
.My current approach is, to compare the constraints of
can('create', 'User', { id: 1 })
with my creation object. In this case it would fail.However there are cases, where one would like to restrict via relations. This is possible for
read/update/delete
since they all rely on Where queries. But not forcreate
. I.e.:I have two approaches to this issue:
Prisma.CreateUserInput
instead ofPrisma.WhereUserInput
➖ repeated logic in prisma client
➖ data such as org.id needs to be available within abilities as well as in query
The second approach has quite some disadvantages. However, the first approach does not work with
ucast
. Do you have an idea from your experience with creating entries?Beta Was this translation helpful? Give feedback.
All reactions