Skip to content

fix: human output no longer displaying undefined#307

Merged
WillieRuemmele merged 12 commits intomainfrom
phale/W-11216045
Jun 3, 2022
Merged

fix: human output no longer displaying undefined#307
WillieRuemmele merged 12 commits intomainfrom
phale/W-11216045

Conversation

@peternhale
Copy link
Copy Markdown
Contributor

What does this PR do?

fixed case for subquery data displaying undefined
fixed case where subquery returns more than one row

What issues does this PR fix or reference?

@W-11216045@

@W-11216045@
fixed case for subquery data displaying undefined
fixed case where subquery returns more than one row
(formattedColumns[field] = {
header: field.toUpperCase(),
get: (row): string => get(row, field) as string,
get: (row): string => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified the get to first check if the field, as given, can be referenced directly, This solves case where property has a name like foo.bar. If cannot be directly referenced then delegate to get

const childRecords = getArray(childO, 'records', []);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
childRecords.forEach((record: unknown) => {
childRecords.forEach((record: unknown, index) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There can be more than one child record from a subquery, Account record can have more than one contact associated to it. For subquery records 2-n a synthetic record needs to be added to the results to produce output like

force:data:soql:query -u myalias -q Select name, (Select FirstName, LastName from Contacts) from Account
 NAME                            CONTACTS.FIRSTNAME CONTACTS.LASTNAME 
 ─────────────────────────────── ────────────────── ───────────────── 
 Test                                                                 
 Sample Account for Entitlements Peter              Hale              
                                 null               Test              
Total number of records retrieved: 2.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a NUT to cover this case?

value: value ? value : chalk.bold('null'),
});
if (!index) {
Reflect.defineProperty(result as Record<string, unknown>, `${child.toString()}.${key}`, {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add subquery data to first query record

value: value ? value : chalk.bold('null'),
});
} else {
Reflect.defineProperty(newResult, `${child.toString()}.${key}`, {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add subquery data to subquery records 2-n

});
}
newResults.push(result);
newResults.push(result, ...subResults);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push parent and additional subquery records into result.

@WillieRuemmele
Copy link
Copy Markdown
Contributor

QA:

in the org, create an Account
add 2 Contacts to that account with the New Contact button

 ➜  sfdx force:data:soql:query -q "SELECT Name, (SELECT LastName FROM Contacts) FROM Account"
 NAME                            CONTACTS.LASTNAME 
 ─────────────────────────────── ───────────────── 
 Sample Account for Entitlements undefined         
 SF                              undefined         
Total number of records retrieved: 2.
Querying Data... done
➜  dreamhouse-lwc git:(main) ✗  hub:(DevHub) scratch:(test-6t6kwus58zn0@example.com)
 ➜  ../../oss/plugin-data/bin/run force:data:soql:query -q "SELECT Name, (SELECT LastName FROM Contacts) FROM Account"
 NAME                            CONTACTS.LASTNAME 
 ─────────────────────────────── ───────────────── 
 Sample Account for Entitlements                   
 SF                              Ruemmele          
                                 Dom   

original query printed undefined, the new output will add both Contacts' last name to the query correctly

@WillieRuemmele WillieRuemmele merged commit d989fad into main Jun 3, 2022
@WillieRuemmele WillieRuemmele deleted the phale/W-11216045 branch June 3, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants