Support multiple fk relations (#1308)
This commit is contained in:
parent
57ead01624
commit
6a962583b0
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue