👋 hey I am trying to model something
# spicedb
s
👋 hey I am trying to model something with a caveat. Right now I have a caveat like
num > 25
. But I want that 25 to come from a relation i.e. when I store an object, I want to set that number instead of hard coding it for every check. Is this possible at all?
From a pseudo code perspective, I want to do something like this:
Copy code
organization:simonsplaygroundorg#numberoftasks:25
Then be able to use that number in a caveat
j
you can store the context on a relationship
Copy code
organization:simonsplaygroundorg#somerelation@someobject:someobjectid[somecaveat:{"number_of_tasks": 25}]
s
oh cool!
and the somecaveat has to be on the field that you store the relationship with?
Sorry if that terminology is off I am purely evaluating spicedb for the second day 😂
j
no worries!
these are good questions
so yes
you'd need to define it on the relation
Copy code
relation somerelation: someobject with somecaveat
s
but then how do I access it in the caveat?
j
its given to it
Copy code
caveat somecaveat(number_of_tasks: int) {

}
s
OK but then, can I pass in a second argument per check?
j
yes
Copy code
caveat somecaveat(number_of_tasks: int, found_number_of_tasks: ) {
  number_of_tasks  >= found_number_of_tasks
}
that would only succeed if the
found_number_of_tasks
in the Check context was smaller or equal to the
number_of_tasks
on the relationship
s
this is awesome, let me give it a go.
Thank you Joey!
That worked, thank you so much for the guidance Joey
j
of course!
let me know if you have any other questions
s
I have one more if I may
If I have a definition like so:
Copy code
definition app {
  relation organization: organization
  
  relation reader: user
  relation editor: user

  permission edit = editor
  permission view = reader + edit + organization->members
}
How can I add a relation that ensures that the user is part of the organization? I was
app:appname#edit@user:user123
which works but it doesn't enforce that the user is part of the org.
j
apologies! Discord didn't ding me
looking now
where do you want the enforcement to occur?