I stumbled uppon the same problem like in neo4j - Relationship between three nodes. I am new in Neo4J and wanted to model a relational database as a graph.
I have three types of data, A, B and C. An instance of B, B1, can belong to an instance of C, C1, and an instance of A, A1 can belong to B1 and C1, but if and only if B1 belongs to C1. The problem here is that, i can also have A1 belonging to B2 which belongs to C1 and A1 also belonging to B1 which belongs to C2. These would be three legit, separate combinations. So, in my DB, i would have a join table where in a record i would keep the combination of the three ids, expressing the relationships formed by the instances.
Now, from what i can figure, hyperedges is something like what i am searching(http://neo4j.com/docs/stable/cypher-cookbook-hyperedges.html). I was thinking, for starters, to add relationships like these:
A-[:PART_OF]->TRIPLE
B-[:PART_OF]->TRIPLE
C-[:PART_OF]->TRIPLE
1st problem/question: if a type B instance was to be deleted then the triple node would remain. I am guessing i would have to handle this in some way when deleting things?
2nd problem/question: My main question is, would it be more efficient if i added some more relationships? For example A-[:BELONGS_TO]->C. So, if i wanted all type C instances that A1 belongs to, i could have the results back with one hop. The relationship traversals would be less in number than the "triple" type nodes that would have to be visited. I think basically i am asking how Neo4j is looking for patterns internally(Where does it start, does it re-examine nodes etc). Because i am guessing(maybe wrongfully) if i want the Cs that A1 belongs to, i would write something like:
match A1-[:PART_OF]->triple<-[:PART_OF]-C return C
How would that query work? First retrieve all triples A1 is part of, then those all C types are part of and finally return the matches?
Any hints? Thanks in advance.