Reputation: 3934
Let's say I wanted to merge new edges into my graph between 2 adjacent nodes (so that after the operation the edges in question are doubled so to speak).
I have the following record returned by graph.cypher.execute(<some query>)
:
| p
---+----------------------------
1 | (:A)-[:r]->(:B)-[:r]->(:C)
Now I would like to double the edges (A,B) and (B,C). For that i wrote this code:
for record in graph.cypher.execute(<some query>):
for rel in record[0]:
self.graph.cypher.execute("MERGE "+str(self.graph.node(rel.start_node.ref))+"-[:new]->"+str(self.graph.node(rel.end_node.ref)))
However, I do not get new edges between the existing nodes but two new relationships with a total of 4 new nodes, because apparently NEO4J does not interpret str(self.graph.node(rel.start_node.ref))
and str(self.graph.node(rel.end_node.ref))
as referring to the existing nodes in the graph. How can I remedy this?
Upvotes: 1
Views: 689
Reputation: 3934
self.graph.create(rel(r.start_node, "new", r.end_node))
does it.
needs from py2neo import rel
Upvotes: 1