cancel
Showing results for 
Search instead for 
Did you mean: 

Different property values based on the direction of the relationship

I need to model 'Friend' relationship in neo4j. Relationship may have types like 'Buddy' or 'Friend'. For example, A and B are friends. A considers B as a 'Buddy' and B considers A as a 'Friend'. I see two options to model this.

  1. Create two relationships. A --> B with property 'type' = 'Buddy' and B --> A with property 'type' = 'Friend'.
  2. Create one relationship with two properties 'Forward_Type' and 'Backward_Type'. If the relationship is from A to B, 'Forward_Type' = 'Buddy' and 'Backward_Type' will be 'Friend'

Please let me know which one is good in terms of traversing complexity/performance. Thank you.

4 REPLIES 4

shan
Graph Buddy

I'd suggest you create two edges:

CREATE (A)-[:BUDDY]->(B)
CREATE (B)-[:FRIEND]->(A)

Note that BUDDY and FRIEND are not properties here, they are relationship types.

If we create two relationship types, is it still possible to traverse people regardless of the type of the relation? For example, to retrieve all people who know person A.

mark_andrews
Node Link
MATCH (n)-[:BUDDY|FRIEND]->(A) RETURN n;

It's much faster this way as well since you can't index relationship properties.

Thank you very much for the help