I searched everywhere for a solution plus stared at this problem for so long, and i still cannot figure why apoc.create.vRelationship does not create edges correctly. Created a toy example to demonstrate the issue. I have product/company graph where Products are connected like "Product p2 NEEDED_IN Product p1" and "Company C1 DEVELOPES Product p1". In the example above "Company C2 DEVELOPES Product p2", then "Company C2 SUPPLIES_PRODUCT to C1". I am trying to create temporary relationship "Company C2 SUPPLIES_PRODUCT to C1" between Companies whose Products depends on each other via apoc.create.vRelationship.
Data set
CREATE (C1:Company{name : 'C1'})
CREATE (C2:Company{name : 'C2'})
CREATE (C3:Company{name : 'C3'})
CREATE (p1:Product{PRODUCT_NAME:'p1'})
CREATE (p2:Product{PRODUCT_NAME:'p2'})
CREATE (p3:Product{PRODUCT_NAME:'p3'})
CREATE (p4:Product{PRODUCT_NAME:'p4'})
CREATE (p5:Product{PRODUCT_NAME:'p5'})
CREATE (p6:Product{PRODUCT_NAME:'p6'})
CREATE (p2)-[:NEEDED_IN]->(p1)
CREATE (p3)-[:NEEDED_IN]->(p1)
CREATE (p4)-[:NEEDED_IN]->(p2)
CREATE (p5)-[:NEEDED_IN]->(p2)
CREATE (p6)-[:NEEDED_IN]->(p2)
CREATE (C1)-[:DEVELOPES]->(p1)
CREATE (C2)-[:DEVELOPES]->(p2)
CREATE (C2)-[:DEVELOPES]->(p3)
CREATE (C3)-[:DEVELOPES]->(p4)
CREATE (C1)-[:DEVELOPES]->(p5)
CREATE (C1)-[:DEVELOPES]->(p6)
Cypher Query
MATCH (C2:Company)-[:DEVELOPES]->(p2)-[:NEEDED_IN]->(p1)<-[:DEVELOPES]-(C1:Company{name : 'C1'})
MATCH (C3:Company)-[:DEVELOPES]->(p3)-[:NEEDED_IN]->(p2)
WITH DISTINCT C1, C2, C3, p1, p2, p3
RETURN C1, C2, C3, apoc.create.vRelationship(C2,'SUPPLIES_PRODUCT',{products_provided: collect(p2.PRODUCT_NAME), name: 'level1'} ,C1), apoc.create.vRelationship(C3,'SUPPLIES_PRODUCT',{products_provided: collect(p3.PRODUCT_NAME), name: 'level2'} ,C2)
The problem : I expect 2 edges coming out of Company C2 to Company C1. One edge for Product P2 and one for Product P3. However, that is not the case. I have an edge that includes duplicate Product P2, and Product P3 is entirely missing. apoc.create.vRelationship sometimes creates duplicate relationships, and sometimes misses a relationship. Any help is appreciated.
Versions: Neo4j 3.5