I need some help in a scenario related to relationship.
For E.g. currently i am having a relationship between two nodes A and B like below.
A-[rel]->B
now it may be possible that in future it get changed . for all properties and data for relationhsip rel need to switch a node C
now relationship is
A-[rel]->C
how i can do that ?
rel can not be duplicate . if 2nd scenario comes then scenario 1 should be removed.
I would like to follow the versioning approach for keeping the data for historical purposes. Here is my approach for your scenario.
Here I add a 'active' property to the relationship and set that to 'yes':
with
CREATE (h:hospital {name:"xyz"})
CREATE (n:owner {name:"abc"})
CREATE (h)-[:OWNER {active:"yes"}]->(n)
RETURN h,n;
Create a new owner node and connect it to hospital node setting the OWNER property to 'yes' . Prior to this set the OWNER property to 'no'.
Cypher query:
MATCH (c:hospital)-[r:OWNER]->(d:owner)
WHERE c.name="xyz" AND d.name = "abc"
SET r.active = "no"
CREATE (f:owner {name:"cde"})
CREATE (c)-[:OWNER {active:"yes"}]->(f)
RETURN c, d, f;
After this you can delete the old owner node with appropriate queries.
Remember to query on [:OWNER {active:"yes"}] relationship.
Looks like refactoring relationship works strictly for only two nodes: (a)-[:]->(b).
When applied this to (a)-[:]->(b)-[:]-(d).... scenario it deleted all the nodes past (b).
Before:
After:
Recently I learnt this hard way (losing data). No mention of this in APOC user guide.
-Kamal
Above result could easily be obtained with Query 1 and Qurery 2 without redirecting relationship. This shows that refactoring relationship works strictly for only two nodes: (a)-[:]->;(b).
Your original relationship was from the :Country node to the :Zip node with id 1234.
Your call redirected the relationship (deleted the old and created a new relationship) from the :Country node to the :Zip2 node with id 2135. The relationships previously in place (from the :Zip with id 1234 to the :Place node, and the relationship from the :Place node to the :Type node) were not changed in any way, nor were any nodes deleted.
To make sure it's clear, the refactor call is only used to redirect a single relationship from (or to) one node to another, it does not refactor an entire path.
I'm not entirely clear on what outcome were you were expecting to see and how you thought the refactor call was meant to work, but if you open up a separate question with what kind of thing you are attempting to do I may be able to help you with such a query.