Skip to content

Support "acyclic" constraint on relationships #172

@IanRogers

Description

@IanRogers

CIR-2017-172

Related to #173

I want to be able to model a DAG (Directed Acyclic Graph) in cypher. So I need to be able to ensure that when a relationship is created then it doesn't create a loop.

I guess it could be done by remembering to code all the creates in a transaction, something like

# start transaction
match (a:T {key:'val1'}), (b:T {key:'val2'}) create (a)-[:R]->(b)
match p = (a:T {key:'val1'})-[:R*]-(a) return p limit 1
# abort transaction if there's now a loop

But that feels really clumsy and prone to developer errors. NB. see also neo4j/neo4j#8667

It would be much nicer to be able to say something like

create constraint on ()-[r:R]-() assert acyclic(r)

and have match (a:T {key:'val1'}), (b:T {key:'val2'}) create (a)-[:R]->(b) throw an error automatically if it would make a loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions