mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
fix 1st level deep filter
This commit is contained in:
parent
85eeb4aef2
commit
511ca55461
@ -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);
|
||||
|
||||
@ -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}.`;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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, {
|
||||
|
||||
@ -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;
|
||||
},
|
||||
|
||||
@ -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'];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user