From 596adb5f61a4734f69c56bd7ec06385df4f36a56 Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Mon, 30 Apr 2018 17:14:13 +0200 Subject: [PATCH] Fix 1059 --- packages/strapi-admin/package.json | 2 +- .../config/layout.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/strapi-plugin-upload/package.json | 2 +- .../package.json | 2 +- packages/strapi-utils/lib/models.js | 32 ++++++------------- 8 files changed, 16 insertions(+), 30 deletions(-) diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index 04ac2246f5..9eac64685b 100755 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -52,4 +52,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-content-manager/config/layout.json b/packages/strapi-plugin-content-manager/config/layout.json index 9e26dfeeb6..0967ef424b 100644 --- a/packages/strapi-plugin-content-manager/config/layout.json +++ b/packages/strapi-plugin-content-manager/config/layout.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/packages/strapi-plugin-content-manager/package.json b/packages/strapi-plugin-content-manager/package.json index 89233057dc..ee4c444e68 100755 --- a/packages/strapi-plugin-content-manager/package.json +++ b/packages/strapi-plugin-content-manager/package.json @@ -47,4 +47,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-content-type-builder/package.json b/packages/strapi-plugin-content-type-builder/package.json index ff8efb2e0e..ca91fa6380 100755 --- a/packages/strapi-plugin-content-type-builder/package.json +++ b/packages/strapi-plugin-content-type-builder/package.json @@ -51,4 +51,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-settings-manager/package.json b/packages/strapi-plugin-settings-manager/package.json index 07964c35c5..fa6e21ccbd 100755 --- a/packages/strapi-plugin-settings-manager/package.json +++ b/packages/strapi-plugin-settings-manager/package.json @@ -48,4 +48,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-upload/package.json b/packages/strapi-plugin-upload/package.json index 7f1327c7d6..f6b2f97ced 100644 --- a/packages/strapi-plugin-upload/package.json +++ b/packages/strapi-plugin-upload/package.json @@ -48,4 +48,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-users-permissions/package.json b/packages/strapi-plugin-users-permissions/package.json index f83955c0ce..62a426cc4d 100644 --- a/packages/strapi-plugin-users-permissions/package.json +++ b/packages/strapi-plugin-users-permissions/package.json @@ -55,4 +55,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js index bba48ada14..5ee5910d72 100755 --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -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';