This commit is contained in:
Jim Laurie 2018-04-30 17:14:13 +02:00
parent f91be5ce63
commit 596adb5f61
8 changed files with 16 additions and 30 deletions

View File

@ -52,4 +52,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -47,4 +47,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -51,4 +51,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -48,4 +48,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -55,4 +55,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -140,30 +140,16 @@ module.exports = {
types.current = 'modelD';
// We have to find if they are a model linked to this key
_.forIn(_.omit(models, currentModelName || ''), model => {
Object.keys(model.attributes)
.filter(key => key === association.via)
.forEach(attr => {
const attribute = model.attributes[attr];
const model = models[association.model]
const attribute = model.attributes[association.via];
if (attribute.hasOwnProperty('via') && attribute.via === key && attribute.hasOwnProperty('collection') && attribute.collection !== '*') {
types.other = 'collection';
// Break loop
return false;
} else if (attribute.hasOwnProperty('model') && attribute.model !== '*') {
types.other = 'model';
// Break loop
return false;
} else if (attribute.hasOwnProperty('collection') || attribute.hasOwnProperty('model')) {
types.other = 'morphTo';
// Break loop
return false;
}
});
});
if (attribute.hasOwnProperty('via') && attribute.via === key && attribute.hasOwnProperty('collection') && attribute.collection !== '*') {
types.other = 'collection';
} else if (attribute.hasOwnProperty('model') && attribute.model !== '*') {
types.other = 'model';
} else if (attribute.hasOwnProperty('collection') || attribute.hasOwnProperty('model')) {
types.other = 'morphTo';
}
} else if (association.hasOwnProperty('model')) {
types.current = 'model';