Merge where and relation payload

This commit is contained in:
Kamal Bennani 2018-10-10 00:34:39 +02:00
parent 7801aac50f
commit 0ed9b7643a
No known key found for this signature in database
GPG Key ID: 4513063CDB1A1C25
3 changed files with 16 additions and 13 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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
}
};
};
}
};