<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tomasteicher/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tomasteicher">@tomasteicher</a>: 'When I want to delete a node, i need to delete all its relationships first. Maybe it would be good when there would be a method that do all this deletions together.</p>
<p dir="auto">For example, when I am deleting a node, I am using this my custom method</p>
<p dir="auto">/**<br>
* delete all nodes from first parameter with all its relationships from the<br>
* database<br>
*<br>
* <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/param/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/param">@param</a> nodes ArrayList of nodes to delete<br>
*/<br>
public static void deleteNodesWithRelationships(ArrayList nodes) {<br>
if (nodes == null || nodes.size() == 0) {<br>
return;<br>
} else {<br>
Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();<br>
params.put("nodes", nodes);<br>
String query = "START n = node({nodes}) MATCH n-[r]-() DELETE n, r";<br>
ExecutionResult result = executionEngine.execute(query, params);<br>
}<br>
}</p>
<p dir="auto">I am not sure whether this method is optimal for its task. Therefore it would be better when this task (remove node with its relationships) would be part of Neo4j Java API, for example as a method of GraphDatabaseService interface.'</p>
<p dir="auto">This a request for a convenience modifier described in the subject.  This would allow Cypher queries to be constructed without having to figure out how to add additional clauses to delete the nodes' relationships.</p>
<p dir="auto">Rationale:</p>
<p dir="auto">For a "simple" delete this is easy enough:</p>
<p dir="auto">START n = node(...) MATCH n-[r?]-() DELETE r,n</p>
<p dir="auto">But when the query gets more complex, the clause needed to find the relationships becomes more complex as well.</p>
<p dir="auto">It would be convenient if the Cypher query could simply indicate the intent of deleting certain nodes and Cypher takes care of doing whatever needs to be done to make that happen.  It could look something like:</p>
<p dir="auto">START n = node(...), m=node(...) MATCH [match clause that may find other nodes]  FORCE DELETE n, m, other_nodes...</p>
<p dir="auto">This is in keeping with query languages like SQL, in which you define a predicate.  That predicate is then used  to either return the result or delete the result without requiring additions to the predicate itself.</p>