src/Services/DeleteNode.js
function addCascadeDeleteNode(neode, builder, from_alias, relationship, aliases, to_depth) {
    if ( aliases.length > to_depth ) return;

    const rel_alias = from_alias + relationship.name() + '_rel';
    const node_alias = from_alias + relationship.name() + '_node';
    const target = neode.model( relationship.target() );

    // Optional Match
    builder.optionalMatch(from_alias)
        .relationship(relationship.relationship(), relationship.direction(), rel_alias)
        .to(node_alias, relationship.target());

    // Check for cascade deletions
    target.relationships().forEach(relationship => {
        switch ( relationship.cascade() ) {
            case 'delete':
                addCascadeDeleteNode(neode, builder, node_alias, relationship, aliases.concat(node_alias), to_depth);
                break;

            // case 'detach':
            //     addDetachNode(neode, builder, node_alias, relationship, aliases);        
            //     break;
        }
    });

    // Delete it
    builder.detachDelete(node_alias);
}
function addCascadeDeleteNode(neode, builder, from_alias, relationship, aliases, to_depth) {
    if ( aliases.length > to_depth ) return;

    const rel_alias = from_alias + relationship.name() + '_rel';
    const node_alias = from_alias + relationship.name() + '_node';
    const target = neode.model( relationship.target() );

    // Optional Match
    builder.optionalMatch(from_alias)
        .relationship(relationship.relationship(), relationship.direction(), rel_alias)
        .to(node_alias, relationship.target());

    // Check for cascade deletions
    target.relationships().forEach(relationship => {
        switch ( relationship.cascade() ) {
            case 'delete':
                addCascadeDeleteNode(neode, builder, node_alias, relationship, aliases.concat(node_alias), to_depth);
                break;

            // case 'detach':
            //     addDetachNode(neode, builder, node_alias, relationship, aliases);        
            //     break;
        }
    });

    // Delete it
    builder.detachDelete(node_alias);
}
function addCascadeDeleteNode ( neode , builder , from_alias , relationship , aliases , to_depth ) { if ( aliases . length > to_depth ) return ; const rel_alias = from_alias + relationship . name ( ) + '_rel' ; const node_alias = from_alias + relationship . name ( ) + '_node' ; const target = neode . model ( relationship . target ( ) ) ; // Optional Match builder . optionalMatch ( from_alias ) . relationship ( relationship . relationship ( ) , relationship . direction ( ) , rel_alias ) . to ( node_alias , relationship . target ( ) ) ; // Check for cascade deletions target . relationships ( ) . forEach ( relationship => { switch ( relationship . cascade ( ) ) { case 'delete' : addCascadeDeleteNode ( neode , builder , node_alias , relationship , aliases . concat ( node_alias ) , to_depth ) ; break ; // case 'detach': //     addDetachNode(neode, builder, node_alias, relationship, aliases);         //     break; } } ) ; // Delete it builder . detachDelete ( node_alias ) ; }
Add a recursive cascade deletion

@param {Neode}            neode          Neode instance
@param {Builder}          builder        Query Builder
@param {String}           alias          Alias of node
@param {RelationshipType} relationship   relationship type definition
@param {Array}            aliases        Current aliases
@param {Integer}          to_depth       Maximum depth to delete to
Add a recursive cascade deletion