Support multiple fk relations (#1308)

This commit is contained in:
Sakib Hasan 2017-04-04 18:23:43 -04:00 committed by GitHub
parent 57ead01624
commit 6a962583b0
1 changed files with 3 additions and 1 deletions

View File

@ -1342,6 +1342,8 @@ DataSource.prototype.discoverSchemas = function(modelName, options, cb) {
nameMapper = function mapName(type, name) {
if (type === 'table' || type === 'model') {
return fromDBName(name, false);
} else if (type == 'fk') {
return fromDBName(name + 'Rel', true);
} else {
return fromDBName(name, true);
}
@ -1464,7 +1466,7 @@ DataSource.prototype.discoverSchemas = function(modelName, options, cb) {
schema.options.relations = {};
foreignKeys.forEach(function(fk) {
var propName = nameMapper('column', fk.pkTableName);
var propName = nameMapper('fk', (fk.fkName || fk.pkTableName));
schema.options.relations[propName] = {
model: nameMapper('table', fk.pkTableName),
type: 'belongsTo',