lib/index.js
function getBelongsToManyName(hasManyThrough) {
    var tfkc            = hasManyThrough.throughForeignKeyConstraint(),
        as              = tfkc.foreignKey(0).name(),                                            // company_id
        throughTableName    = hasManyThrough.through().name(),
        relationName    = hasManyThrough.throughForeignKeyConstraintToSelf().name(),
        tableName       = hasManyThrough.table().name(),
        camelCase       = getSpecificConfig(tableName, 'generate.relationAccessorCamelCase'),
        prefix          = getSpecificConfig(tableName, 'generate.prefixForBelongsTo');          // related

    if (getSpecificConfig(tableName, 'generate.addRelationNameToManyToMany')) {
        if (getSpecificConfig(tableName, 'generate.stripFirstTableNameFromManyToMany')) {
            relationName = relationName.replace(new RegExp('^' + tableName + '[_-]?', 'i'), '');     // cart_cart_line_items -> cart_line_item
        }
        as = inflection.singularize(relationName) + '_' + as;
    } else if (getSpecificConfig(tableName, 'generate.addTableNameToManyToMany')) {
        as = inflection.singularize(throughTableName) + '_' + as;
    }

    if (as.match(/_id$/i)) {
        as = as.replace(/_id$/i, '');                                                       // company_id -> company
    } else {
        as = prefix + '_' + as;                                                             // company -> related_company
    }
    if (camelCase) {
        as = inflection.camelize(inflection.underscore(as), true);
    }
    return inflection.pluralize(as);
}
function getBelongsToManyName(hasManyThrough) {
    var tfkc            = hasManyThrough.throughForeignKeyConstraint(),
        as              = tfkc.foreignKey(0).name(),                                            // company_id
        throughTableName    = hasManyThrough.through().name(),
        relationName    = hasManyThrough.throughForeignKeyConstraintToSelf().name(),
        tableName       = hasManyThrough.table().name(),
        camelCase       = getSpecificConfig(tableName, 'generate.relationAccessorCamelCase'),
        prefix          = getSpecificConfig(tableName, 'generate.prefixForBelongsTo');          // related

    if (getSpecificConfig(tableName, 'generate.addRelationNameToManyToMany')) {
        if (getSpecificConfig(tableName, 'generate.stripFirstTableNameFromManyToMany')) {
            relationName = relationName.replace(new RegExp('^' + tableName + '[_-]?', 'i'), '');     // cart_cart_line_items -> cart_line_item
        }
        as = inflection.singularize(relationName) + '_' + as;
    } else if (getSpecificConfig(tableName, 'generate.addTableNameToManyToMany')) {
        as = inflection.singularize(throughTableName) + '_' + as;
    }

    if (as.match(/_id$/i)) {
        as = as.replace(/_id$/i, '');                                                       // company_id -> company
    } else {
        as = prefix + '_' + as;                                                             // company -> related_company
    }
    if (camelCase) {
        as = inflection.camelize(inflection.underscore(as), true);
    }
    return inflection.pluralize(as);
}
function getBelongsToManyName ( hasManyThrough ) { var tfkc = hasManyThrough . throughForeignKeyConstraint ( ) , as = tfkc . foreignKey ( 0 ) . name ( ) , // company_id throughTableName = hasManyThrough . through ( ) . name ( ) , relationName = hasManyThrough . throughForeignKeyConstraintToSelf ( ) . name ( ) , tableName = hasManyThrough . table ( ) . name ( ) , camelCase = getSpecificConfig ( tableName , 'generate.relationAccessorCamelCase' ) , prefix = getSpecificConfig ( tableName , 'generate.prefixForBelongsTo' ) ; // related if ( getSpecificConfig ( tableName , 'generate.addRelationNameToManyToMany' ) ) { if ( getSpecificConfig ( tableName , 'generate.stripFirstTableNameFromManyToMany' ) ) { relationName = relationName . replace ( new RegExp ( '^' + tableName + '[_-]?' , 'i' ) , '' ) ; // cart_cart_line_items -> cart_line_item } as = inflection . singularize ( relationName ) + '_' + as ; } else if ( getSpecificConfig ( tableName , 'generate.addTableNameToManyToMany' ) ) { as = inflection . singularize ( throughTableName ) + '_' + as ; } if ( as . match ( / _id$ / i ) ) { as = as . replace ( / _id$ / i , '' ) ; // company_id -> company } else { as = prefix + '_' + as ; // company -> related_company } if ( camelCase ) { as = inflection . camelize ( inflection . underscore ( as ) , true ) ; } return inflection . pluralize ( as ) ; }
Calculates belongsToMany relation name based on table, column and config.
@private
@param {object} hasManyThrough - pg-structure foreign key constraint object.
@returns {string} - Name for the belongsToMany relationship.
Calculates belongsToMany relation name based on table column and config .