Search code examples
neo4jgraph-databases

Graph Database Modelling Confusion


I'm trying to learn neo4j and coming from a relational database, I'm a bit confused about the proper way to model the following:

Account        Application    ApplicationModule
 acct_id        app_id         app_mod_id
 name           name           app_id
                               name

AccountModuleAccess
 id
 acct_id
 app_mod_id
 can_read
 can_delete
 can_update
 can_insert

I can see the following relationship

Application->ApplicationModule->AccountModuleAccess

and

Account->AccountModuleAccess

But what confuses me is AccountModuleAccess relationship with both Account and AccountModule


Solution

  • I think it will help to consider what in your model should be a relationship, vs what should be a node (most of the attributes are fairly clear).

    Note that AccountModuleAccess is really all about how an account relates to an account module, most of these can probably be modeled as relationships.

    You can also get rid of the concept of foreign keys, use relationships for those.

    Consider this model:

    (:Account)-[:CAN_READ|CAN_DELETE|CAN_UPDATE|CAN_INSERT]->(:ApplicationModule)
    (:ApplicationModule)-[:MODULE_OF]->(:Application)
    

    To save room I put all the relationships at once, but each of those would be a separate relationship between :Account and :ApplicationModule.