Skip to content

Commit 59d7ea0

Browse files
committed
Fixed SObject prefix
Added new property for fields that have an object prefix paustint/fusekit/#2226
1 parent 12d72d4 commit 59d7ea0

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

debug/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var soqlParserJs = require('../dist');
22

33
const query = `
4-
SELECT COUNT_DISTINCT(Company) FROM Lead
4+
SELECT Id, c.FirstName, c.LastName
5+
FROM Contact c
6+
LIMIT 1
57
`;
68

79
const parsedQuery = soqlParserJs.parseQuery(query, { logging: true });

lib/SoqlComposer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class Compose {
6969

7070
private parseQuery(query: Query, isSubquery: boolean = false): string {
7171
const fieldData: FieldData = {
72-
fields: this.parseFields(query.fields, query.sObjectAlias ? true : false).map(field => ({
72+
fields: this.parseFields(query.fields).map(field => ({
7373
text: field,
7474
isSubquery: false,
7575
prefix: '',
@@ -170,12 +170,12 @@ export class Compose {
170170
return output;
171171
}
172172

173-
private parseFields(fields: Field[], hasSObjectAlias: boolean): string[] {
173+
private parseFields(fields: Field[]): string[] {
174174
return fields
175175
.map(field => {
176176
if (utils.isString(field.text)) {
177-
if (hasSObjectAlias) {
178-
return `${utils.get(field.alias, '.')}${field.text}`;
177+
if (field.objectPrefix) {
178+
return `${utils.get(field.objectPrefix, '.')}${field.text}`;
179179
} else {
180180
return `${field.text}${utils.get(field.alias, '', ' ')}`;
181181
}

lib/SoqlListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class Listener implements SOQLListener {
215215
// All fields need to update to remove the alias from relationships
216216
this.getSoqlQuery().fields.forEach(field => {
217217
if (field.text && field.text.startsWith(`${ctx.text}.`)) {
218-
field.alias = ctx.text;
218+
field.objectPrefix = ctx.text;
219219
field.text = field.text.replace(`${ctx.text}.`, '');
220220
if (field.relationshipFields.length > 2) {
221221
field.relationshipFields = field.relationshipFields.splice(1);

lib/models/SoqlQuery.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface SelectStatement {
3131
export interface Field {
3232
text?: string;
3333
alias?: string;
34+
objectPrefix?: string;
3435
relationshipFields?: string[];
3536
fn?: FunctionExp;
3637
subqueryObjName?: string; // populated if subquery

test/TestCases.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,12 @@ export const testCases: TestCase[] = [
867867
fields: [
868868
{
869869
text: 'Name',
870-
alias: 'c',
870+
objectPrefix: 'c',
871871
},
872872
{
873873
text: 'Account.Name',
874874
relationshipFields: ['Account', 'Name'],
875-
alias: 'c',
875+
objectPrefix: 'c',
876876
},
877877
],
878878
subqueries: [],
@@ -989,11 +989,11 @@ export const testCases: TestCase[] = [
989989
fields: [
990990
{
991991
text: 'Id',
992-
alias: 'a',
992+
objectPrefix: 'a',
993993
},
994994
{
995995
text: 'Name',
996-
alias: 'a',
996+
objectPrefix: 'a',
997997
},
998998
{
999999
subqueryObjName: 'ChildAccounts',
@@ -1007,7 +1007,7 @@ export const testCases: TestCase[] = [
10071007
fields: [
10081008
{
10091009
text: 'Id',
1010-
alias: 'a2',
1010+
objectPrefix: 'a2',
10111011
},
10121012
],
10131013
subqueries: [],
@@ -1018,7 +1018,7 @@ export const testCases: TestCase[] = [
10181018
fields: [
10191019
{
10201020
text: 'Id',
1021-
alias: 'a1',
1021+
objectPrefix: 'a1',
10221022
},
10231023
],
10241024
subqueries: [],

0 commit comments

Comments
 (0)