I have a graph in which versioning information is stored as [:ADD] or [:REMOVE] relations between nodes. I want to replace those rels by another model, based on [:UPDATE] rels with property type and timestamp.
Currently
MATCH (n:tocversion)-[r:ADD]->(m)
RETURN n.version,id(m)
returns this (as expected)
n.version,id(m)
1,13
1,14
2,15
2,16
3,17
3,18
3,19
3,20
4,21
4,22
Now I thought I could collect the versions and m's and use them as a basis to create rels in the new model. Like this.
MATCH (n:tocversion)-[r:ADD]->(m),(t:toc)
WITH t,COLLECT(n.version) AS versions, COLLECT(m) AS ms
FOREACH(i IN versions |
FOREACH(m1 IN [ms[i]]|
CREATE (t)-[r1:UPDATE {type:"ADD", version:versions[i]}]->(m1)))
However, the rels are created in a way I don't understand, because
MATCH (t:toc)-[r:`UPDATE`]->(b) RETURN r.version,r.type,id(b)
returns
r.version,r.type,id(b)
1, ADD, 14
1, ADD, 14
2, ADD, 15
2, ADD, 15
2, ADD, 16
2, ADD, 16
2, ADD, 16
2, ADD, 16
3, ADD, 17
3, ADD, 17
instead of the expected
r.version,r.type,id(b)
1, ADD, 13
1, ADD, 14
2, ADD, 15
2, ADD, 16
3, ADD, 17
3, ADD, 18
3, ADD, 19
3, ADD, 20
4, ADD, 21
4, ADD, 22