I query the following path:
Company
has Employees
has User
From User
I want to find all HasRights
edges which point back to the current Company
(the user also has rights on other companies).
See TODO in code below:
Gremlin Query:
g.V()
.hasLabel("Company")
.project("Company","Employees")
// >>>> this is the company I want to filter by below
.by(__.identity())
.by(__.out("Has").hasLabel("Employee").not(__.has("IsDeleted",true)).has("Status",neq(5).and(neq(4)))
.project("Employee","User","Rights")
.by(__.identity())
.by(__.out("Has").hasLabel("User"))
.by(__.out("Has").hasLabel("User").outE("HasRight")
// >>>> TODO here I need to filter by above company
.where(__.inV().hasLabel("Company")))
.fold())
.fold())
Simplifying things a little, just to make the example smaller, in cases like this you should be able to use this pattern:
g.V().hasLabel('Company').as('c').
out('Has').hasLabel('Employee').
out('Has').hasLabel('User').
outE('HasRight).where(inV().as('c'))