https://authzed.com logo
#spicedb
"Reverse" Relationships
# spicedb
b

braden.g

09/25/2023, 2:29 AM
I think my
room
definition is fine, but my
user
block might be way off. I captured assertions that I'm trying to satisfy in the assertions tab
v

vroldanbet

09/25/2023, 10:55 AM
This seems fine - It's just that you haven't written the
peers
relationships This works as you expect now: https://play.authzed.com/s/GsIXdz8f7r_a/assertions
b

braden.g

09/25/2023, 1:05 PM
Is there a way for this to work without duplicating those relationships?
If I have
room:1#occupant@user1
and
room:1#occupant@user2
Then I'd expect spiceDB to find that path
v

vroldanbet

09/25/2023, 1:21 PM
If you are modelling with a reverse relationship, no, there is no way to avoid it for now. I don't have the details of your business domain, but there may be a different way of modelling this altogether that does not require reverse relationships.
b

braden.g

09/25/2023, 1:26 PM
> there is no way to avoid it for now Should I take this to mean that "reverse relationships" are something that spiceDB wants to support eventually? > I don't have the details of your business domain The example is pretty close to my real business domain. We want the system to have users. Users will have access to resources. Users may only see each other if they can see a common resource.
v

vroldanbet

09/25/2023, 2:00 PM
>Should I take this to mean that "reverse relationships" are something that spiceDB wants to support eventually? Potentially, although I dont have a good picture what it would entail: https://github.com/authzed/spicedb/issues/356
>The example is pretty close to my real business domain. We want the system to have users. Users will have access to resources. Users may only see each other if they can see a common resource. A potential alterantive is to run
LookupSubjects
over
room:<id>#enter
. It will list the users that have permission to enter on a given room. That would spare you the
peers
relation
b

braden.g

09/25/2023, 2:37 PM
Thanks. That works for a single room ID. I would like that to be variable though. "List all users that a specific user shares any room with"
v

vroldanbet

09/25/2023, 4:34 PM
I see, so all the users across all rooms the subject has access to
I think the schema you propose is the best route I can think of with your current requirements. It requires you to write 2 relationships by occupation. It's fine to write those reverse relationships, you just need to be mindful of capacity calculations for large scale. The write can be done atomically via
WriteRelationships
b

braden.g

09/25/2023, 5:12 PM
Gotcha. Thanks for the help