Filter O2M collections with a subquery instead of joins to prevent cartesian products (#4278)

* Cherry-picked fix for 4078 from mssql-to-success branch

* Only use o2m joins in subqueries

* Allow more array nesting in query params

* Clarify naming

* Return empty nested o2m sets as array

Co-authored-by: Martijn Boland <martijn@taiga.nl>
Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Martijn Boland
2021-03-04 22:58:13 +01:00
committed by GitHub
parent 3065d65b0c
commit bed7890a6b
3 changed files with 46 additions and 21 deletions

View File

@@ -159,11 +159,6 @@ function getDBQuery(
applyQuery(table, dbQuery, queryCopy, schema);
// Nested filters use joins to filter on the parent level, to prevent duplicate
// parents, we group the query by the current tables primary key (which is unique)
// ref #3798
dbQuery.groupBy(`${table}.${primaryKeyField}`);
return dbQuery;
}
@@ -266,7 +261,7 @@ function mergeWithParentItems(
itemChildren = itemChildren.slice(0, nestedNode.query.limit ?? 100);
}
parentItem[nestedNode.fieldKey] = itemChildren.length > 0 ? itemChildren : null;
parentItem[nestedNode.fieldKey] = itemChildren.length > 0 ? itemChildren : [];
}
} else if (nestedNode.type === 'm2a') {
for (const parentItem of parentItems) {