mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 16:16:20 +00:00
Merge pull request #3190 from strapi/fix/issue-3189
Cast arrays and build mongo where match with a $and
This commit is contained in:
commit
541b00041a
@ -29,12 +29,10 @@ const buildQuery = ({ model, filters = {}, populate = [], aggregate = false } =
|
||||
const buildSimpleQuery = ({ model, filters, populate }) => {
|
||||
const { where = [] } = filters;
|
||||
|
||||
const wheres = where.reduce(
|
||||
(acc, whereClause) => _.assign(acc, buildWhereClause(whereClause)),
|
||||
{}
|
||||
);
|
||||
const wheres = where.map(buildWhereClause);
|
||||
const findCriteria = wheres.length > 0 ? { $and: wheres } : {};
|
||||
|
||||
let query = model.find(wheres).populate(populate);
|
||||
let query = model.find(findCriteria).populate(populate);
|
||||
query = applyQueryParams({ query, filters });
|
||||
|
||||
return Object.assign(query, {
|
||||
|
||||
@ -106,7 +106,13 @@ const buildQuery = ({ model, filters = {}, ...rest }) => {
|
||||
});
|
||||
|
||||
const { type } = _.get(assocModel, ['attributes', attribute], {});
|
||||
return { field, operator, value: castValueToType({ type, value }) };
|
||||
|
||||
// cast value or array of values
|
||||
const castedValue = Array.isArray(value)
|
||||
? value.map(val => castValueToType({ type, value: val }))
|
||||
: castValueToType({ type, value: value });
|
||||
|
||||
return { field, operator, value: castedValue };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user