Skip to content

Commit 26719c5

Browse files
authored
Merge pull request #161 from paustint/bug-160
getFlattenedFields issue with aliased fields
2 parents d3db27f + 08c8b3e commit 26719c5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 4.2.2
4+
5+
August 1, 2021
6+
7+
#160 - `getFlattenedFields()` Did not return correct results if a normal field used an alias, such as `SELECT Count(Id), Name account_name FROM Account GROUP BY Name`
8+
39
## 4.2.1
410

511
June 18, 2021

src/api/public-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function getFlattenedFields(
178178
.flatMap(field => {
179179
switch (field.type) {
180180
case 'Field': {
181-
return field.field;
181+
return field.alias || field.field;
182182
}
183183
case 'FieldFunctionExpression': {
184184
let params = getParams(field);

test/public-utils-test-data.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,34 @@ export const testCases: FlattenedObjTestCase[] = [
559559
560560
},
561561
},
562+
{
563+
testCase: 16,
564+
expectedFields: ['expr0', 'account_name'],
565+
query: {
566+
fields: [
567+
{
568+
type: 'FieldFunctionExpression',
569+
functionName: 'COUNT',
570+
parameters: ['Id'],
571+
isAggregateFn: true,
572+
rawValue: 'Count(Id)',
573+
},
574+
{
575+
type: 'Field',
576+
field: 'Name',
577+
alias: 'account_name',
578+
},
579+
],
580+
sObject: 'Account',
581+
groupBy: [
582+
{
583+
field: 'Name',
584+
},
585+
],
586+
},
587+
sfdcObj: {
588+
expr0: 10,
589+
account_name: 'Account 1',
590+
},
591+
},
562592
];

0 commit comments

Comments
 (0)