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;