I am trying to copy all r{} where (a {uuid1})-[r]-(c) for use in (b {uuid2})-[r]-(c), while maintaining the original (a)-[r]-(c). It's for versioning purposes - b is an updated node of a, and I want to copy over all relationships a had over to b.
I have uuid uniqueness constraints in place for both nodes and relationships.
I have read and tested how to move relationships from a to b with apoc.refactor.to and apoc.refactor.from. I've also tried apoc.refactor.cloneNodesWithRelationships.
But I've yet seen how to clone relationships without creating unwanted nodes.
Michael can you add more details? Is this a case where you only need to copy relationships (but direct them to another node) or do you need to copy nodes as well?
Andrew, it would be a situation where a node was copied but given a different name and then had an exact copy of all the relationships the other node did.
I'm giving this a shot call apoc.refactor.cloneNodesWithRelationships([node1,node2,…]).
This is my current query:
create (n:Lease {id: "Test2"})
with n as newLease
match (m:Lease {id: "Test"})
CALL apoc.refactor.cloneNodesWithRelationships([newLease,m]) YIELD input, output
RETURN *
So far it returns a copy of the node but none of the relationships. it makes sense as some nodes have a unique ID constraint. This is basically needs to be a copy and past with a rename. I hope this helps.
You may be able to use just cloneNodes(), as this has some optional parameters that will let it clone relationships as well, and skip properties in the cloning (which should get around the unique id issue).
You can see the entire signature for usage with:
call apoc.help('cloneNodes')
Example of usage, skipping the id property (confirmed that this doesn't trigger unique constraint violations):
match (n:Lease {id: "Test"})
call apoc.refactor.cloneNodes([n], true, ['id']) yield output, input, error
set output.id = "Test2"
return input, output, error