问题
I'm trying to combine / merge a path into a new relationship. The problem is that I'm not interested in storing it but rather return it as a result of a cypher query.
Lets say I have something like this:
(a)-[:CALLS_METHOD]->(b)-[:RETURNS_TYPE]->(c)
How can I create a temporary relationship like this one:
(a)-[:DEPENDS_ON]->(c)
Only for a result of that particular query, so that I don't have to store it. Because I'm really only interested in the dependency from a
to c
and not the details about of that dependency.
回答1:
You can't return a relationship from the database that doesn't exist. The purpose of the queries is to return stuff that does exist.
Perhaps what you're interested in is inferred pairs, rather than a relationship. Something like:
MATCH (a)-[r:CALLS_METHOD|RETURNS_TYPE*]->(b)
RETURN a, "depends on", b
Your other alternative is to materialize/save the relationship, and then query for it:
MATCH (a)-[r:CALLS_METHOD|RETURNS_TYPE*]->(b)
CREATE a-[newRel:DEPENDS_ON]->b
RETURN newRel;
But this has the side-effect of creating it.
来源:https://stackoverflow.com/questions/23645257/cypher-temp-relationship