4
votes

I am currently implementing a graph database in which persons are allocated to projects (of a customer) using an allocation node. Customers or Projects may or may not exist already, the Allocation node should be unique (each Allocation node can only have one incoming and one outgoing relationship). The code below works, but duplicates the Project->Customer relationship when both already exists in the database. How can I prevent this?

MATCH (p:Person {id:1})
MERGE (c:Customer {id:1})
MERGE (pr:Project {id:1})
CREATE (p)-[:HAS_ALLOCATION]->(a:Allocation)-[:ON_PROJECT]->(pr)-[:HAS_CUSTOMER]->(c)
RETURN a,p,pr,c;

a busy cat

1

1 Answers

0
votes

You should try both MERGE and CREATE UNIQUE in place of your CREATE clause and see if that fixes your issue.