diff --git a/packages/strapi-hook-bookshelf/lib/relations.js b/packages/strapi-hook-bookshelf/lib/relations.js index 55b51a0ce6..0b8695510c 100644 --- a/packages/strapi-hook-bookshelf/lib/relations.js +++ b/packages/strapi-hook-bookshelf/lib/relations.js @@ -37,6 +37,16 @@ module.exports = { generateMatchStage: function (qb) { return (strapiModel, filters) => { + if (!filters) { + return undefined; + } + + // 1st level deep filter + if (filters.where) { + this.generateMatchStage(qb)(strapiModel, { relations: filters.where }); + } + + // 2nd+ level deep filter _.forEach(filters.relations, (value, key) => { if (key !== 'relations') { const association = strapiModel.associations.find(a => a.alias === key); diff --git a/packages/strapi-hook-mongoose/lib/relations.js b/packages/strapi-hook-mongoose/lib/relations.js index 682a7a5adc..a6999233ce 100644 --- a/packages/strapi-hook-mongoose/lib/relations.js +++ b/packages/strapi-hook-mongoose/lib/relations.js @@ -101,6 +101,18 @@ module.exports = { let acc = []; + // 1st level deep filter + if (filters.where) { + acc.push( + ...generateMatchStage( + strapiModel, + { relations: filters.where }, + { prefixPath } + ) + ); + } + + // 2nd+ level deep filter _.forEach(filters.relations, (value, key) => { if (key !== 'relations') { const nextPrefixedPath = `${prefixPath}${key}.`; diff --git a/packages/strapi-plugin-graphql/services/Query.js b/packages/strapi-plugin-graphql/services/Query.js index 26c307c843..989e78e89d 100644 --- a/packages/strapi-plugin-graphql/services/Query.js +++ b/packages/strapi-plugin-graphql/services/Query.js @@ -32,7 +32,7 @@ module.exports = { if (_.isPlainObject(value)) { const flatObject = this.convertToQuery(value); _.forEach (flatObject, (_value, _key) => { - result[key + '.' + _key] = _value; + result[`${key}.${_key}`] = _value; }); } else { result[key] = value; diff --git a/packages/strapi-plugin-graphql/services/Resolvers.js b/packages/strapi-plugin-graphql/services/Resolvers.js index dfbeb680e6..51235dc7c2 100644 --- a/packages/strapi-plugin-graphql/services/Resolvers.js +++ b/packages/strapi-plugin-graphql/services/Resolvers.js @@ -398,7 +398,7 @@ module.exports = { queryOpts.skip = convertedParams.start; switch (association.nature) { - case "manyToMany": + case "manyToMany": { const arrayOfIds = (obj[association.alias] || []).map( related => { return related[ref.primaryKey] || related; @@ -413,7 +413,7 @@ module.exports = { ...where.where, }).where; break; - // falls through + } default: // Where. queryOpts.query = strapi.utils.models.convertParams(name, { diff --git a/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js b/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js index cf90842d72..860ac31e09 100644 --- a/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js +++ b/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js @@ -18,10 +18,9 @@ module.exports = { } } }) - .fetchAll({ - withRelated: populate || _.keys(_.groupBy(_.reject(this.associations, { autoPopulate: false }), 'alias')) - }); - + .fetchAll({ + withRelated: populate || _.keys(_.groupBy(_.reject(this.associations, { autoPopulate: false }), 'alias')) + }); return records ? records.toJSON() : records; }, diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js index ec80dc1658..de1545ad24 100644 --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -11,11 +11,6 @@ const path = require('path'); const _ = require('lodash'); const pluralize = require('pluralize'); -// Following this discussion https://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric this function is the best implem to determine if a value is a valid number candidate -const isNumeric = (value) => { - return !_.isObject(value) && !isNaN(parseFloat(value)) && isFinite(value); -}; - // Constants const ORDERS = ['ASC', 'DESC'];