mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +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 aggregateStages = mergeStages(populateStage, matchStage);
|
||||
|
||||
const result = <%= globalID %>.aggregate([
|
||||
{
|
||||
$match: filters.where, // Direct relation filter
|
||||
},
|
||||
...aggregateStages
|
||||
])
|
||||
const result = <%= globalID %>.aggregate(aggregateStages)
|
||||
.skip(filters.start)
|
||||
.limit(filters.limit);
|
||||
|
||||
|
||||
@ -10,12 +10,7 @@ module.exports = {
|
||||
const matchStage = hook.load().generateMatchStage(this, filters); // Nested relation filter
|
||||
const aggregateStages = mergeStages(populateStage, matchStage);
|
||||
|
||||
const result = this.aggregate([
|
||||
{
|
||||
$match: filters.where || {}, // Direct relation filter
|
||||
},
|
||||
...aggregateStages
|
||||
]);
|
||||
const result = this.aggregate(aggregateStages);
|
||||
|
||||
if (_.has(filters, 'start')) result.skip(filters.start);
|
||||
if (_.has(filters, 'limit')) result.limit(filters.limit);
|
||||
|
||||
@ -364,7 +364,7 @@ module.exports = {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -453,6 +453,7 @@ module.exports = {
|
||||
this.processValues({ model, models, convertor, postProcessValue }),
|
||||
this.processPredicates({ model, models, convertor }),
|
||||
this.processGeneratedResults(),
|
||||
this.mergeWhereAndRelationPayloads()
|
||||
])(_filter);
|
||||
},
|
||||
|
||||
@ -680,5 +681,17 @@ module.exports = {
|
||||
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