I have neo4j node and relationship schema in neomodel as given below. Now I need to create a function so that it takes the uid of the PersonRel and delete the relationship between the two persons connected by this relationship. I couldn't find it in the documentation: https://neomodel.readthedocs.io/en/latest/
class PersonRel(StructuredRel):
uid = StringProperty()
created_at = DateTimeProperty(
default=lambda: datetime.now(pytz.utc)
)
weight = FloatProperty()
direction = StringProperty()
class PersonNode(StructuredNode):
uid = UniqueIdProperty()
label = StringProperty(required=True)
description = StringProperty()
related_to = RelationshipFrom("PersonNode", "related_to", model=PersonRel)
created_at = DateTimeProperty(
default=lambda: datetime.now(pytz.utc)
)
As Raj pointed out, it is possible in Neomodel to write any raw cypher query as well. However, in the documentation, the process is not clearly described.
The following code finally helped me to get the required results:
from neomodel import db as neodb
neodb.cypher_query("MATCH ()-[rel {uid:{uid}}]-() delete rel", {"uid": rel_id})
To be noted, the params are required to be passed as a dictionary, which is not mentioned in the documentation. Also, {uid:{uid}}
- in this part of the query, the inner uid, which is again is curly braces, is a variable which should be passed in params. But the outer braces are a part of cypher syntax, so neomodel code doesn't consider that as a variable. Also, there is no need to add quotes around {uid}
.