From 27e6975c4a026170b8c3bb2e7fa319e779b0d9e1 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 6 Jan 2020 11:51:03 +0100 Subject: [PATCH] Do not overwritten morphAssoc populates --- packages/strapi-connector-mongoose/lib/mount-models.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/strapi-connector-mongoose/lib/mount-models.js b/packages/strapi-connector-mongoose/lib/mount-models.js index 44e93f0f24..871771ede8 100644 --- a/packages/strapi-connector-mongoose/lib/mount-models.js +++ b/packages/strapi-connector-mongoose/lib/mount-models.js @@ -8,6 +8,10 @@ const utils = require('./utils'); const relations = require('./relations'); const { findComponentByGlobalId } = require('./utils/helpers'); +const isPolymorphicAssoc = assoc => { + return assoc.nature.toLowerCase().indexOf('morph') !== -1; +}; + module.exports = ({ models, target, plugin = false }, ctx) => { const { instance } = ctx; @@ -117,7 +121,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => { */ const morphAssociations = definition.associations.filter( - association => association.nature.toLowerCase().indexOf('morph') !== -1 + isPolymorphicAssoc ); const populateFn = createOnFetchPopulateFn({ @@ -366,6 +370,7 @@ const createOnFetchPopulateFn = ({ if (definition.modelType === 'component') { definition.associations + .filter(assoc => !isPolymorphicAssoc(assoc)) .filter(ast => ast.autoPopulate !== false) .forEach(ast => { this.populate({ path: ast.alias });