Fix buildQuery for polymorphic relations

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
Convly 2020-10-19 15:36:28 +02:00
parent e1e2dd3419
commit 07c38420d4

View File

@ -167,7 +167,7 @@ const buildDeepQuery = ({ model, filters, search, populate }) => {
$in: ids,
},
},
null,
null
)
.populate(populate);
@ -445,12 +445,14 @@ const buildLookupMatch = ({ assoc, assocModel, filters = {} }) => {
},
{
$match: {
$expr: {
$and: defaultMatches.concat(
{ $eq: [`$${assoc.via}.ref`, '$$localId'] },
{ $eq: [`$${assoc.via}.${assoc.filter}`, assoc.alias] }
),
},
$and: defaultMatches.concat({
$expr: {
$and: [
{ $eq: [`$${assoc.via}.ref`, '$$localId'] },
{ $eq: [`$${assoc.via}.${assoc.filter}`, assoc.alias] },
],
},
}),
},
},
];