Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-17-2018 07:55 PM
Hi,
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.
Any suggestions?
Many thanks.
PS, Before posting, I've read the following:
07-02-2019 04:14 AM
Did you ever get any good feedback on this? Or figure it out? I've got a similar situation.
07-02-2019 09:13 AM
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?
07-02-2019 09:46 AM
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.
07-09-2019 07:54 AM
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.
07-09-2019 08:40 AM
Ok this is now working. The only issue is that if you have a uniqueness constraint on a node ID then if fails.
match (n:Lease {id: "Test"})
call apoc.refactor.cloneNodesWithRelationships([n]) yield output, input
set output.id = "Test2"
return *
07-09-2019 11:04 AM
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
All the sessions of the conference are now available online