Spider
Spider

Reputation: 915

Is there a way to create a UNIQUE constraint on relationships in Neo

In Neo4J it is possible to create a UNIQUE constraints on nodes like this:

CREATE CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE

Is it possible to do the same with relationships.

Upvotes: 0

Views: 202

Answers (2)

cybersam
cybersam

Reputation: 66967

If necessary, you can work around the lack of uniqueness constraint support for relationship types by "reifying" the relationships as nodes.

For example, instead of using this data model (where :BORROWS(id) must be unique, which is not supported):

(:Person)-[:BORROWS {id: 123}]->(:Book)

you can use something like this (where :Borrowing(id) must be unique, which is supported):

(:Person)-[:PERFORMS]->(:Borrowing {id: 123})-[:ON]->(:Book)

Upvotes: 1

Lju
Lju

Reputation: 590

It's not possible to apply unique constraints on relationships out of the box.

Upvotes: 1

Related Questions