'Recursive deletion of hierarchy branches
@param node_ids: the parent node IDs of the branches to be deleted
@param cascade: cascade call, do not commit (internal use)
@return: number of deleted nodes, or None if cascade failed'

def delete(self, node_ids, cascade=False):

    if (not self.config):
        return None
    tablename = self.tablename
    total = 0
    for node_id in node_ids:
        children = self.children(node_id)
        if children:
            result = self.delete(children, cascade=True)
            if (result is None):
                if (not cascade):
                    current.db.rollback()
                return None
            else:
                total += result
        from s3query import FS
        query = (FS(self.pkey.name) == node_id)
        resource = current.s3db.resource(tablename, filter=query)
        success = resource.delete(cascade=True)
        if success:
            self.remove(node_id)
            total += 1
        else:
            if (not cascade):
                current.db.rollback()
            return None
    if ((not cascade) and total):
        self.dirty(tablename)
    return total
