Reputation: 123
I have a database with classes users, groups, and networks. Users can have out_ edges to groups or networks. Groups can have out_ edges only to networks. There are three different types of edges, admin, write, and read.
I want to be able to retrieve networks a user has permissions to. The easiest way to do this would be to look at the edges connecting users, groups, and networks. I am trying the following:
select from (traverse out() from <User Record RID>
while $depth <=2
AND ( (@class = 'group' AND <edgeType = write>
OR (@class = 'network' AND <edgeType = read>)
OR @class ='user') )
where @class = 'network'
How can I write the boolean
<edgeType = write>
in the context of the of the current traversal.
Upvotes: 1
Views: 2110
Reputation: 9060
From a vertex (you're jumping from vertex to vertex skipping edges with out()) You can use inE() to get the incoming edge and outE(). So try to add:
inE().@class = 'WriteEdge'
If you have one class per edge type (suggested). Or you can also do:
inE('WriteEdge').size() > 0
Otherwise you could not skip edges in traversal but traverse vertex and edge, adding WHILE conditions that match edges and vertices. Example:
select from (traverse outV(), outE() from <User Record RID>
while $depth <=4
AND ... )
where @class = 'network'
Another option is move forward and check back the traversed vertices and edges with the functions:
Use -1 to get last traversed. -2 the one before last, etc.
Upvotes: 2