Search code examples
neo4jgraph-databasesrelationshipsarangodb

Conditional Relationship in Graph DB


How would a graph model handle a conditional relationship like:

(Alice -[Dates]-> Bob)  
Where [Dates] exists IF and ONLY IF 
(Bob -[Owns]-> Ferrari) is true

Besides just querying, I'm wondering whether the relationship be applied by the database engine based on the condition or whether this needs to be managed in the application.


Solution

  • I can't speak for arangodb, but for neo4j this bit has to be addressed by the application. The bits of schema that you can assert about graphs don't address what kinds of relationships can exist off of a node type. Contingent relationships like what you're talking about are a step further than that even.

    Doing validation like this can be more complex than it first appears. Let's say Bob owns a Ferrari. And so Alice dates Bob (so shallow!). All fine and well -- whether enforced by the application or the database. OK now, Bob sells his Ferrari. What should the database do?

    1. Should Bob be prohibited from selling his ferrari? (i.e. delete of that relationship fails)
    2. Should Alice be forced to break up with Bob? (I.e. delete of that dates relationship....brutal!)
    3. Should some nasty error be thrown?

    These are domain-specific considerations. You'd want to do this in your application layer so that you could think through those validation conditions, and do the right thing. Even if the graph database did support it, it's not clear you'd want to use the graph database's default enforcement policy (whatever that would be).