Reputation: 2766
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)
)
Upvotes: 2
Views: 1194
Reputation: 2766
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}
.
Upvotes: 1
Reputation: 4052
I use Py2Neo so, I am not familiar with the Neomodel. If you don't find any option to find and delete relationship by the property, you can choose to delete it with the standalone Cypher query.
You can execute the standalone cypher query in Neomodel like:
db.cypher_query(query, params)
Your delete query would be like:
MATCH ()-[rel]-() WHERE rel.uid={{uid}} DELETE rel
Upvotes: 2