1
votes

I've seen a previous topic about duplicates, but here is a use case a bit different. I'm managing Part assemblies like a Bill Of Material. each node should be verionnable. I want to handle this versioning by duplicating the node and every relationship to this node. This will create a lot of nodes, and relationships but that's the only way to manage this I think. What is the easiest way to run this with cypher?

I've seen how to create the node, now I need to duplicate the relationships.

1
do you mean from java or cypher ?Michael Hunger
could be from cypher, but I'm fine with a complementary programming solution (I'm using PHP to send cypher queries).Yoann Maingon

1 Answers

2
votes

You definitely want to do this with some kind of programming language. But here is a little cypher example so you can start to experiment. I recently did something similar. One thing to be aware of that is since you are creating new versions of the same of objects with the essentially the same data you have some limitations with uniqueness constraints. In your case with BOM you probably have many uniques keys to choose from though. My data was a little fuzzier. I ended up creating a new label for each new version and i added a uniqueness constraint on name for every label version. Then I indexed name across the database. That suggestion was courtesy of Michael Hunger

// match 2 specific nodes of a particular version and their relationship
MATCH (a:Node)-[r1:ASSEMBLED_WITH]-(b:Node) 
WHERE a.name = 'Node 1' 
AND a.version = 1 
AND b.name = 'Node 2' 
AND b.version = 1

// create copies of the nodes and change the relationship
CREATE (c:Node) 
SET c = a, c.version = 3 
CREATE (d:Node) 
SET d = b, d.version = 3

//create a copy of the relationship and change the version of it
CREATE (c)-[r2:ASSEMBLED_WITH]->(d) 
SET r2 = r1, r2.version = 3