versae / neo4j-rest-client

Object-oriented Python library to interact with Neo4j standalone REST server
http://neo4j-rest-client.rtfd.org
GNU General Public License v3.0
264 stars 73 forks source link

How would I delete all relationships of certain type for a node? #128

Closed ahrennsiva closed 8 years ago

ahrennsiva commented 8 years ago

I have generated a set of nodes along with relationships & I would like to delete all relationships of a certain type for that node. I have student nodes and major nodes that are connected, and upon deletion of a major by a student, I want to remove the relationship of this type. How would I go about doing this?

versae commented 8 years ago

The fastest way is using a Cypher query

match (node { id_prop: XX })-[r:RELATIONSHIP_TYPE]->() delete r;

Using the neo4jrestclient API you would need to iterate over all the relationships and delete them one by one. It can be done in a transaction, but I would still recommend using a Cypher query.

for rel in node.relationships.outgoing(types=["RELATIONSHIP_TYPE"]):
    rel.delete()