neo4jcyphergraph-databasesproject-planning

Neo4j/Cypher : do not allow a relationship


I am creating a PERT tool, and adapting this tutorial to my case.

What I want to do is forbidding the creation of relationships, and the creation of properties:

  1. The START node (which is an :EndPoint, not an :Activity) should not have predecessors, only successors

  2. The FINISH node (which is an :EndPoint, not an :Activity) should not have successors, only predecessors

  3. No CYCLE allowed

    • Each :Activity directly preceding by START cannot have other activities as predecessors
    • Each :Activity (in+)directly predecessor of a activities cannot have these activities as predecessors.

I have not found a way to block these relationships creations. The constraints do not seem to be what I want to do, the UNIQUENESS is not at all what I am looking for.

I tried to take the problem in an other way :

  1. Authorise only successors property for the START:EndPoint
  2. Authorise only predecessors property for the FINISH:EndPoint

but for the 3rd point, I have no idea, and the "reverse-thinking" could be a solution, but I did not find how to apply it.

If you have any idea, even not working, but giving a new vision, I would really appreciate.


Solution

  • Contrary to what is custom here I'm going to give an opinion. The reason being that you're actually not talking about restrictions at the level of the database (aka schema) but restrictions at the level of your problem (aka business rules).

    There are lots of ways to implement business logic the main (and probably the best) one being ... in your application logic.

    A Neo4j specific one would be to use user defined procedures. Not unlike the use of stored procedures and triggers that you might use to solve similar problems in an RDBMS such as Oracle.

    Hope this helps.

    Regards, Tom