0

For recursive breakdown structures, is it better to model as ... a. Group HAS Subgroup... or b. Subgroup PART_OF Group ?? .... Some neo4j tutorials imply model both (the parent_of and child_of example) while the neo4j subtype tutorials imply that either will work fine (generally going with PART-OF).

Based on experience with neo4j, is there a practical reason for choosing one or the other or use both?

Dave
  • 45
  • 4

1 Answers1

1

[UPDATED]

Representing the same logical relationship with a pair of relationships (having different types) in opposite directions is a very bad idea and a waste of time and resources. Neo4j can traverse a single relationship just as easily from either of its nodes.

With respect to which direction to pick (since we do not want both), see this answer to a related question.

Community
  • 1
  • 1
cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Just to note, there are exceptions of course, driven by the needs of your data. A big one is relationships which are not necessarily reciprocal. For example if a :Person has a :Follows relationship to another :Person, that doesn't logically imply that the other :Person follows back...it will require a second relationship in the other direction. Similar situations may occur for relationships of different types. – InverseFalcon Dec 08 '16 at 01:50
  • @InverseFalcon I understand your point. But my answer still holds, since it recommends against always using a pair of relationships (having different types) in opposite directions. I have updated my answer to hopefully make that more clear. – cybersam Dec 08 '16 at 01:54
  • I should have clarified my comment wasn't any kind of criticism of your answer, yours is absolutely correct, this was more of a note for Dave and others to keep in mind. – InverseFalcon Dec 08 '16 at 02:07
  • And, after reading the direction question, I would infer that the PARENT_OF relation would be preferred as (all) children have a parent (PERSON) but not all PERSONs have a child. Same for GROUP and subgroups. ... Point up not down. – Dave Dec 08 '16 at 14:48
  • 1
    @Dave Actually, that consideration should not matter. If there are no technical reasons to pick one direction, I would pick whichever one feels more natural to you for the data model, or even whichever one results in a shorter name for the relationship type. – cybersam Dec 08 '16 at 15:52
  • Thank you both, cybersam and @InverseFalcon. Very helpful. As an old RDBM information engineer, the child using a foreign key to point to the parent feels more natural. Thanks for the quick responses. – Dave Dec 08 '16 at 19:24