Can I have a Constraint that a specific Relationship exists between two nodes/labels?

So I create a node labelled User and another node labelled Profile which are connected with HAS_PROFILE i.e. (user:User)-[rel:HAS_PROFILE]->(profile:Profile).

Can I create a constraint that Profile nodes always have a HAS_PROFILE relationship coming from User nodes?

Unfortunately not at this time.

We definitely like this idea, it's been on our backlog, but then there's a lot of feature requests on our backlog. It's a matter of prioritizing and planning. While I have no doubt we'll get this one eventually, I don't have any idea on when that will happen.

You could probably implement a trigger for this, but you'd need to add the logic yourself for checking when a node is created or a relationship removed.

1 Like

I'd sure like to see constraints on relationship from-to. For the dyslexics, it's way too easy to make the relationship go in the wrong direction and not realize the mistake.

In case you do, there is this APOC function: call apoc.refactor.invert(rel)

1 Like

Indeed, this would be a very helpful feature.

+1

I often explode an entity into two or three, where all three must be present. Lets call that group of 3 closely related nodes a composite.

Currently I believe we have two choices:

1.)
Install the NeoSemantics plugin and use the W3C SHACL (Shapes Constraints Lanugage) to define rules around how nodes and relationships must be connected and named, in addition to their parameter constraints.

2.) Roll your own validations by providing stored procedures to enforce your scheme a labelling scheme on objects in the database. For example say that you want a Person node to always have an 'identity' relationship. Here's just one way of handling it. See image below.