es5/store-bookshelf/lib/related.js
function related(input, relation) {
  return relation.split('.').reduce(function (input, relationSegment) {
    if (_is_many2['default'](input)) {
      // iterate each model and add its related models to the collection
      return input.reduce(function (result, model) {
        var related = model.related(relationSegment);
        return result.add(related.models ? related.models : related);
      }, _related_collection2['default'](input.model, relationSegment));
    }
    return input.related(relationSegment);
  }, input);
}
function related(input, relation) {
  return relation.split('.').reduce(function (input, relationSegment) {
    if (_is_many2['default'](input)) {
      // iterate each model and add its related models to the collection
      return input.reduce(function (result, model) {
        var related = model.related(relationSegment);
        return result.add(related.models ? related.models : related);
      }, _related_collection2['default'](input.model, relationSegment));
    }
    return input.related(relationSegment);
  }, input);
}
function related ( input , relation ) { return relation . split ( '.' ) . reduce ( function ( input , relationSegment ) { if ( _is_many2 [ 'default' ] ( input ) ) { // iterate each model and add its related models to the collection return input . reduce ( function ( result , model ) { var related = model . related ( relationSegment ) ; return result . add ( related . models ? related . models : related ) ; } , _related_collection2 [ 'default' ] ( input . model , relationSegment ) ) ; } return input . related ( relationSegment ) ; } , input ) ; }
Given a model or collection and a dot-notated relation string,
traverse the relations and return the related models from the
last segment in the relation string.

@param {Bookshelf.Model|Bookshelf.Collection} input
@param {String} relation
@return {Bookshelf.Model|Bookshelf.Collection}
Given a model or collection and a dot - notated relation string traverse the relations and return the related models from the last segment in the relation string .