Question

Given a graph where a property on a Relationship is a key to a Node, how can I return the node referenced by the Relationship property?

So, given the graph:

Node(user1 { type: "user", uid: "u1", name: "test user" })
Node(user2 { type: "user", uid: "u2", name: "test user 2})
Node(cat1 { type: "category", cid: "c1", name: "Nice person"})

Rel( (user1)-[:SAYS { cid: "c1" }]->(user2) )

How can I return the cat1 node along with the user2 node given user1?

(e.g., The return values would include the definition of cat1 along with user1 and user2).

The logical starting point is:

START user1 = node:auto_node_index(uid = "u1")
MATCH (user1)-[cat:SAYS]->(user2)
RETURN user1, cat, user2;

but I am clueless where to go from here.

If this becomes too complicated I could always put the properties of the Categories into the relationship (obviously), but that would tend to drive me towards using a secondary storage medium to home the Category definitions (because they would be orphaned nodes in the graph).

Thanks! r/Steve

Was it helpful?

Solution

Hmmm. Fairly easy actually. Typing out the question made me think more clearly about the problem. This works:

START user1 = node:node_auto_index(uid = "u1"), c = node:node_auto_index(type = "category")
MATCH (user1)<-[cat:SAYS]-(user2)
WHERE c.cid = cred.cid
RETURN user1, cat, user2, c;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top