Skip to content

Commit 92bd9e1

Browse files
committed
getFlattenedFields does not correctly handle alias
... for grouped expressions Added check to return alias instead of related field for aggregate exp resolves #31
1 parent 93ce0e9 commit 92bd9e1

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
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+
## 3.0.1
4+
5+
January 7, 20201
6+
7+
1. `getFlattenedFields` did not properly handle the alias for an aggregate function within an aggregate query. (#131)
8+
39
## 3.0.0
410

511
October 14, 2020

src/api/public-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ export function getFlattenedFields(
192192
return param;
193193
});
194194

195+
if (field.alias && (field.isAggregateFn || isAggregateResult)) {
196+
return field.alias;
197+
}
198+
195199
if (field.alias) {
196200
const firstParam = params[0];
197201
// Include the full path and replace the field with the alias

test/public-utils-test-data.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,32 @@ export const testCases: FlattenedObjTestCase[] = [
414414
},
415415
},
416416
},
417+
{
418+
testCase: 13,
419+
expectedFields: ['AccountId', 'AcctCreatedDate'],
420+
query: {
421+
fields: [
422+
{
423+
type: 'Field',
424+
field: 'AccountId',
425+
},
426+
{
427+
type: 'FieldFunctionExpression',
428+
functionName: 'MAX',
429+
parameters: ['Account.CreatedDate'],
430+
isAggregateFn: true,
431+
rawValue: 'MAX(Account.CreatedDate)',
432+
alias: 'AcctCreatedDate',
433+
},
434+
],
435+
sObject: 'Contact',
436+
groupBy: {
437+
field: ['AccountId'],
438+
},
439+
},
440+
sfdcObj: {
441+
AccountId: '0016g00000ETu0HAAT',
442+
AcctCreatedDate: '2020-02-28T03:00:31.000+0000',
443+
},
444+
},
417445
];

0 commit comments

Comments
 (0)