Hi, I started looking into Neo4j this morning, and played with some domain models to see whether it really passes a "whiteboard friendliness" test. I'm really after a persistence solution that makes it straightforward to persist a domain model designed from a DDD perspective, and Neo4j is looking promising so far. The one aspect that's not too clear is how to model n-ary relationships, and I'm curious as to how those of you with experience with Neo4j and graph databases would approach it.
An edge connects two vertices, so in a graph database, a relationship connects two nodes. But when modeling, there are frequently relationships between multiple entities. For example, student John attends a History course at university, and John was referred to the History course by Paul. This relationship relates John, Paul, and the History course. There are a few ways I can think of to model this. 1) A node John has an ATTENDS relationship with node History, and the relationship has a "referrer" property with Paul's ID. Simple, but keeping IDs as properties seems like an anti-pattern. 2) A node Referral has a CREATED_BY relationship with node Paul, a FOR_COURSE relationship with node History, and a TO_STUDENT relationship with node John. It's effectively a three-way join. 3) Same as 2, but with an additional ATTENDS relationship between John and History. This is particularly useful if a course attendant may attend a course without being referred. This might not be the best example in the world, but it should drive my point home: when relationships have a degree higher than 2, relationships need to be modelled as vertices to overcome the binary nature of edges. Is this expected behavior that's part and parcel of graph databases, or am I approaching the modeling incorrectly somehow? My concern is that traversals may become unnatural when this happens. Say I want to iterate over the attendants of a course, and show the name of who referred them when I do so. Will I have the graph database equivalent of n+1 selects because the data I want to extract (referrer name) is in a different node (Paul) to my node of interest (John), instead of in the relationship to it (attends)? Any tips and opinions would be appreciated. Cheers, Emerson _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

