- neo4j 5.26.7 EE, desktop version 2.0, browser version
Well,
I have a relationship p = ()-[h:HAS_TAG]->(r:name)
let me show you what i want to achieve:
p = (n:Node)-[h:HAS_TAG]->(t1:TAG { name : "Donald" })
// which is formally CORRECT
p = (n:DifferentNode)-[r:HAS_TAG]->(t1:TAG { name : "Duck" })
// which is formally CORRECT, because I want to allow different nodes to have the same attribute.name
p = (n:Node)-[h:HAS_TAG]->(t1:TAG { name : "Trump" })
// which is WRONG, because I don't want to allow the same node to have more than one attribute with the same name
My constraint is:
CREATE CONSTRAINT IF NOT EXISTS FOR ()-[r:HAS_TAG]->(t:Tag) REQUIRE t.name IS UNIQUE ON r;
where I mean that Tag attributes
must be unique on the relationship r
but it returns an error which for some reasons, is not as some notices I found on the documentation;
The documentation I've found doesn't mention "relationship existence constraints", the constraints it shows are only on properties on a node or on a relationship, can you point me at the documentation you used?
There is no constraint where you can specify a relationship and related nodes. The constraints are defined a node or a relationship, not a combination of the two. What you want to do is not available.
A possible way to emulate the behaviour you want with the constraints as they are:
CREATE CONSTRAINT IF NOT EXISTS FOR ()-[r:hasTag]->() REQUIRE r.tagName IS UNIQUE
Your tagName
is the unique identifier of :Node
+ the property you want to be unique:
CREATE (A:Node {uuid: $nodeUuid })-[:hasTag {tagName: $nodeUuid + 'name'}]->(B:TAG {name:'4'})
For any node :Node
, only 1 property with a specified property name exists.
Well, it could be a good idea or suggestion for the future!