Reputation: 5587
Apologies I am new to Graphing DB! I have the following basic structure in an OrientDB:
I need to obtain all the permission
associated with a given User
. permission
are always contained in a Role
but a Role
can belong either directly to a User
or to a Team
. I haven't added it to the image but the edges between User > Role
and Team > Role
are has
. And between User > Team
are member
.
My current approach is:
SELECT permission FROM (
TRAVERSE any() FROM #23:0 WHILE $depth <=4
) WHERE @class='Role'
However, I suspect that there is a much more efficient was of achieving this.
Upvotes: 2
Views: 250
Reputation: 2814
Instead of using any()
for traversal, you can use named edges.
Eg. if user -belongsTo-> team
and user,team -hasPermission-> permission
you can write this query like
SELECT FROM (
TRAVERSE out('belongsTo', 'hasPermission') FROM #23:0 WHILE $depth <=2
) WHERE @class='Role'
This will avoid traversal of unwanted branches.
Upvotes: 1