-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many-to-many dependency condition check #85
Comments
Hey! Thanks for the detailed issue. I want to setup a test case for this and then work from there - could you share the relevant parts of your Prisma schema (or a representative example)? |
@alexolivier sure,
|
@alexolivier may I ask if you have any updates on this issue? or suggestion about workarounds? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use Prisma and I have a problem to make a consistent solution for the "is any related item" check with both
prisma-plan-adaptor
andcerbos.checkResources
implementations.So I have
N:M
relations betweenUser
andRole
models.And policy like this:
Option 1
hasUsers1: ({} in R.attr.users)
it works as expected with Prisma plan adapter and returnsKIND_CONDITIONAL
plan with{"NOT":{"users":{"some":{}}}}
filters, but when i check the resource fordelete
action permissions, it returnsEFFECT_ALLOW
. I populate and pass the list of users into thecheckResources
request (ideally, i'd like to avoid this population if possible):and i'm get back
results
as:Option 2
hasUsers2: size(R.attr.users) > 0
- i've tried to use it as alternative solution and it works as expected withcerbos.checkResources
and the same payload as I mentioned above but it seems that Prisma plan adapter doesn't supportsize
method and it throws the error with the following error stack:And the query plan i pass into
queryPlanToPrisma
looks like this:Option 3
hasUsers3: R.attr._count.users > 0
i've tried it as another approach (instead of actual population of the users, just to count the related users) and check this number, in this case it works as expected till the DB request. Prisma throws the error because Role model has no_count
field, which exists in plan-adapter filters:KIND_CONDITIONAL {"NOT":{"_count":{"users":{"gt":0}}}}
.The error says:
Solution?
I've tried to combine the options, like this
hasUsers1or3: ({} in R.attr.users) || (R.attr._count.users > 0)
which kind of makes sense to me, but i didn't find a way to sayqueryPlanToPrisma
via fieldMapper/relationMapper that_count
condition should be ignorred in this case.So I'm looking for advice on how to make it properly?
The text was updated successfully, but these errors were encountered: