build/Services/WriteUtils.js
function addRelationshipToStatement(neode, builder, alias, rel_alias, target_alias, relationship, value, aliases, mode) {
    if (aliases.length > MAX_CREATE_DEPTH) {
        return;
    }

    // Extract Node
    var node_alias = relationship.nodeAlias();
    var node_value = value[node_alias];

    delete value[node_alias];

    // Create Node

    // If Node is passed, attempt to create a relationship to that specific node
    if (node_value instanceof _Node2.default) {
        builder.match(target_alias).whereId(target_alias, node_value.identity());
    }

    // If Primary key is passed then try to match on that
    else if (typeof node_value == 'string' || typeof node_value == 'number') {
            var model = neode.model(relationship.target());

            builder.merge(target_alias, model, _defineProperty({}, model.primaryKey(), node_value));
        }

        // If Map is passed, attempt to create that node and then relate
        else if (Object.keys(node_value).length) {
                var _model = neode.model(relationship.target());
                node_value = _GenerateDefaultValues2.default.async(neode, _model, node_value);

                addNodeToStatement(neode, builder, target_alias, _model, node_value, aliases, mode, _model.mergeFields());
            }

    // Create the Relationship
    builder[mode](alias).relationship(relationship.relationship(), relationship.direction(), rel_alias).to(target_alias);

    // Set Relationship Properties
    relationship.properties().forEach(function (property) {
        var name = property.name();

        if (value.hasOwnProperty(name)) {
            builder.set(rel_alias + '.' + name, value[name]);
        }
    });
}
function addRelationshipToStatement(neode, builder, alias, rel_alias, target_alias, relationship, value, aliases, mode) {
    if (aliases.length > MAX_CREATE_DEPTH) {
        return;
    }

    // Extract Node
    var node_alias = relationship.nodeAlias();
    var node_value = value[node_alias];

    delete value[node_alias];

    // Create Node

    // If Node is passed, attempt to create a relationship to that specific node
    if (node_value instanceof _Node2.default) {
        builder.match(target_alias).whereId(target_alias, node_value.identity());
    }

    // If Primary key is passed then try to match on that
    else if (typeof node_value == 'string' || typeof node_value == 'number') {
            var model = neode.model(relationship.target());

            builder.merge(target_alias, model, _defineProperty({}, model.primaryKey(), node_value));
        }

        // If Map is passed, attempt to create that node and then relate
        else if (Object.keys(node_value).length) {
                var _model = neode.model(relationship.target());
                node_value = _GenerateDefaultValues2.default.async(neode, _model, node_value);

                addNodeToStatement(neode, builder, target_alias, _model, node_value, aliases, mode, _model.mergeFields());
            }

    // Create the Relationship
    builder[mode](alias).relationship(relationship.relationship(), relationship.direction(), rel_alias).to(target_alias);

    // Set Relationship Properties
    relationship.properties().forEach(function (property) {
        var name = property.name();

        if (value.hasOwnProperty(name)) {
            builder.set(rel_alias + '.' + name, value[name]);
        }
    });
}
function addRelationshipToStatement ( neode , builder , alias , rel_alias , target_alias , relationship , value , aliases , mode ) { if ( aliases . length > MAX_CREATE_DEPTH ) { return ; } // Extract Node var node_alias = relationship . nodeAlias ( ) ; var node_value = value [ node_alias ] ; delete value [ node_alias ] ; // Create Node // If Node is passed, attempt to create a relationship to that specific node if ( node_value instanceof _Node2 . default ) { builder . match ( target_alias ) . whereId ( target_alias , node_value . identity ( ) ) ; } // If Primary key is passed then try to match on that else if ( typeof node_value == 'string' || typeof node_value == 'number' ) { var model = neode . model ( relationship . target ( ) ) ; builder . merge ( target_alias , model , _defineProperty ( { } , model . primaryKey ( ) , node_value ) ) ; } // If Map is passed, attempt to create that node and then relate else if ( Object . keys ( node_value ) . length ) { var _model = neode . model ( relationship . target ( ) ) ; node_value = _GenerateDefaultValues2 . default . async ( neode , _model , node_value ) ; addNodeToStatement ( neode , builder , target_alias , _model , node_value , aliases , mode , _model . mergeFields ( ) ) ; } // Create the Relationship builder [ mode ] ( alias ) . relationship ( relationship . relationship ( ) , relationship . direction ( ) , rel_alias ) . to ( target_alias ) ; // Set Relationship Properties relationship . properties ( ) . forEach ( function ( property ) { var name = property . name ( ) ; if ( value . hasOwnProperty ( name ) ) { builder . set ( rel_alias + '.' + name , value [ name ] ) ; } } ) ; }
Add a relationship to the current statement

@param {Neode}           neode           Neode instance
@param {Builder}         builder         Query builder
@param {String}          alias           Current node alias
@param {String}          rel_alias       Generated alias for the relationship
@param {String}          target_alias    Generated alias for the relationship
@param {Relationship}    relationship    Model
@param {Object}          value           Value map
@param {Array}           aliases         Aliases to carry through in with statement
@param {String}          mode        'create' or 'merge'
Add a relationship to the current statement