Make sure aggregated columns are returned

This commit is contained in:
rijkvanzanten
2021-05-25 14:30:15 -04:00
parent c3589d138f
commit ce9296162c

View File

@@ -132,8 +132,11 @@ async function parseCurrentLevel(
nestedCollectionNodes.push(child);
}
/** Always fetch primary key in case there's a nested relation that needs it */
if (columnsToSelectInternal.includes(primaryKeyField) === false) {
/**
* Always fetch primary key in case there's a nested relation that needs it
*/
const childrenContainRelational = children.some((child) => child.type !== 'field');
if (childrenContainRelational && columnsToSelectInternal.includes(primaryKeyField) === false) {
columnsToSelectInternal.push(primaryKeyField);
}
@@ -385,6 +388,17 @@ function removeTemporaryFields(
}
}
// Make sure any new aliased aggregate fields are included
if (ast.query?.aggregate) {
for (const [_operation, aliasMap] of Object.entries(ast.query.aggregate)) {
if (!aliasMap) continue;
for (const [_column, alias] of Object.entries(aliasMap)) {
fields.push(alias);
}
}
}
for (const rawItem of rawItems) {
if (rawItem === null || rawItem === undefined) return rawItem;