Traverse to end node


(Dirtgambit) #1

Hi, im trying to get products where there is a HasHolding relationship then traverse up all products where IsNewEditionOf relationship until I get to the end node and just return the end nodes

in the image layout id only want chart 1 edition 3 and chart 3 edition 4 returned, I can return all editions after the has holding relationship with MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t) return t

I cant seem to narrow it down to getting the last node.

regards


(Dirtgambit) #2

Hi, I ended up doing it this way MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t) WITH holding, tail(collect(t)) AS latesteditions return latesteditions

this gives me the result I expect.


(M. David Allen) #3

You might also try asserting an extra condition on the tail nodes, something like this:

MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t)
WHERE NOT (t)<-[:IsNewEditionOf]-(somethingElse)
RETURN t;

This would give you the leaves and eliminate the intermediates.