我有一组我想要的关系"替换",即创建一个新关系,然后删除旧关系,因为关系是不可变的。
我最初认为:
MATCH paths=()-[:BRANCH]-()
FOREACH (old in relationships(paths) |
WITH startNode(old) as n1, endNode(old) as n2
MERGE (n1)-[new:CONTAINS]-(n2)
SET new = old
DELETE r
)
但不允许WITH
关键字,必须能够弄清楚如何将本地变量分配给起始节点和结束节点。
答案 0 :(得分:7)
您可以再次使用FOREACH来破解WITH,例如:
FOREACH (n1 in [startNode(old)]| ... // you now have an identifier n1 referring to startNode(old)
如果这只是长度1路径,我不确定我是否看到了这样做的价值。你不能这样做:
MATCH (n1)-[old:BRANCH]->(n2)
CREATE (n1)-[new:CONTAINS]->(n2)
DELETE old