"Reverse" Relationships
# spicedb
b
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
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
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
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
> 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
>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
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
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
Gotcha. Thanks for the help