mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user