mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 01:57:56 +00:00
Merge where and relation payload
This commit is contained in:
parent
7801aac50f
commit
0ed9b7643a
@ -30,12 +30,7 @@ module.exports = {
|
|||||||
const matchStage = hook.load().generateMatchStage(<%= globalID %>, filters); // Nested relation filter
|
const matchStage = hook.load().generateMatchStage(<%= globalID %>, filters); // Nested relation filter
|
||||||
const aggregateStages = mergeStages(populateStage, matchStage);
|
const aggregateStages = mergeStages(populateStage, matchStage);
|
||||||
|
|
||||||
const result = <%= globalID %>.aggregate([
|
const result = <%= globalID %>.aggregate(aggregateStages)
|
||||||
{
|
|
||||||
$match: filters.where, // Direct relation filter
|
|
||||||
},
|
|
||||||
...aggregateStages
|
|
||||||
])
|
|
||||||
.skip(filters.start)
|
.skip(filters.start)
|
||||||
.limit(filters.limit);
|
.limit(filters.limit);
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,7 @@ module.exports = {
|
|||||||
const matchStage = hook.load().generateMatchStage(this, filters); // Nested relation filter
|
const matchStage = hook.load().generateMatchStage(this, filters); // Nested relation filter
|
||||||
const aggregateStages = mergeStages(populateStage, matchStage);
|
const aggregateStages = mergeStages(populateStage, matchStage);
|
||||||
|
|
||||||
const result = this.aggregate([
|
const result = this.aggregate(aggregateStages);
|
||||||
{
|
|
||||||
$match: filters.where || {}, // Direct relation filter
|
|
||||||
},
|
|
||||||
...aggregateStages
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (_.has(filters, 'start')) result.skip(filters.start);
|
if (_.has(filters, 'start')) result.skip(filters.start);
|
||||||
if (_.has(filters, 'limit')) result.limit(filters.limit);
|
if (_.has(filters, 'limit')) result.limit(filters.limit);
|
||||||
|
|||||||
@ -364,7 +364,7 @@ module.exports = {
|
|||||||
filter: details.filter,
|
filter: details.filter,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (infos.nature === 'manyToMany' && !association.plugin && definition.orm === 'bookshelf') {
|
if (infos.nature === 'manyToMany' && definition.orm === 'bookshelf') {
|
||||||
ast.tableCollectionName = this.getCollectionName(association, details);
|
ast.tableCollectionName = this.getCollectionName(association, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,6 +453,7 @@ module.exports = {
|
|||||||
this.processValues({ model, models, convertor, postProcessValue }),
|
this.processValues({ model, models, convertor, postProcessValue }),
|
||||||
this.processPredicates({ model, models, convertor }),
|
this.processPredicates({ model, models, convertor }),
|
||||||
this.processGeneratedResults(),
|
this.processGeneratedResults(),
|
||||||
|
this.mergeWhereAndRelationPayloads()
|
||||||
])(_filter);
|
])(_filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -680,5 +681,17 @@ module.exports = {
|
|||||||
return updatedFilter;
|
return updatedFilter;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
mergeWhereAndRelationPayloads: function() {
|
||||||
|
return filter => {
|
||||||
|
return {
|
||||||
|
...filter, // Normally here we need to omit where key
|
||||||
|
relations: {
|
||||||
|
...filter.where,
|
||||||
|
relations: filter.relations
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user