es5/store-bookshelf/lib/create_relation.js
function createRelation(model, relationName, data) {
  if (!model) {
    throw new Error('No model provided.');
  }
  return _transact2['default'](model, function (transaction) {
    var existing = _related2['default'](model, relationName).map(function (rel) {
      return {
        id: _id2['default'](rel),
        type: _type2['default'](rel)
      };
    });
    var all = data.concat(existing);
    // TODO: should i be doing a deep comparison instead?
    var unique = _lodash2['default'].uniq(all, JSON.stringify.bind(null));
    return _relate2['default'](model, {
      name: relationName,
      data: unique
    }, 'add', transaction);
  });
}
function createRelation(model, relationName, data) {
  if (!model) {
    throw new Error('No model provided.');
  }
  return _transact2['default'](model, function (transaction) {
    var existing = _related2['default'](model, relationName).map(function (rel) {
      return {
        id: _id2['default'](rel),
        type: _type2['default'](rel)
      };
    });
    var all = data.concat(existing);
    // TODO: should i be doing a deep comparison instead?
    var unique = _lodash2['default'].uniq(all, JSON.stringify.bind(null));
    return _relate2['default'](model, {
      name: relationName,
      data: unique
    }, 'add', transaction);
  });
}
function createRelation ( model , relationName , data ) { if ( ! model ) { throw new Error ( 'No model provided.' ) ; } return _transact2 [ 'default' ] ( model , function ( transaction ) { var existing = _related2 [ 'default' ] ( model , relationName ) . map ( function ( rel ) { return { id : _id2 [ 'default' ] ( rel ) , type : _type2 [ 'default' ] ( rel ) } ; } ) ; var all = data . concat ( existing ) ; // TODO: should i be doing a deep comparison instead? var unique = _lodash2 [ 'default' ] . uniq ( all , JSON . stringify . bind ( null ) ) ; return _relate2 [ 'default' ] ( model , { name : relationName , data : unique } , 'add' , transaction ) ; } ) ; }
Creates a new relations on a model.

@param {Bookshelf.Model} model - A bookshelf model instance
@param {String} relationName - An object containing the relations.
@param {Array} data - linkage data
@returns {Promise.Bookshelf.Model} The updated model.
Creates a new relations on a model .