Skip to content

Commit b397605

Browse files
author
hknokh2
committed
fix: fix mixed composite externalId relationship handling
1 parent 370f5e2 commit b397605

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/modules/models/script/ScriptObject.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,10 @@ const expandComplexFieldNames = (fieldName: string): string[] => {
8282
if (splitParts.length === 0) {
8383
return [fieldName];
8484
}
85-
const firstPart = splitParts[0] ?? '';
86-
const relationshipPrefixIndex = firstPart.lastIndexOf('.');
87-
const relationshipPrefix = relationshipPrefixIndex > 0 ? firstPart.slice(0, relationshipPrefixIndex + 1) : '';
8885
return splitParts.map((part) => {
8986
if (prefix) {
9087
return part.includes('.') ? part : `${prefix}${part}`;
9188
}
92-
if (relationshipPrefix && !part.includes('.')) {
93-
return `${relationshipPrefix}${part}`;
94-
}
9589
return part;
9690
});
9791
}
@@ -3263,7 +3257,12 @@ export default class ScriptObject {
32633257
void this;
32643258
if (fieldName.includes('.')) {
32653259
const relationshipName = fieldName.split('.')[0] ?? fieldName;
3266-
return Common.getFieldNameId(undefined, relationshipName);
3260+
let idFieldName = Common.getFieldNameId(undefined, relationshipName);
3261+
if (idFieldName === relationshipName && (relationshipName.endsWith('__r') || relationshipName.endsWith('__pr'))) {
3262+
idFieldName = Common.replaceLast(relationshipName, '__pr', '__pc');
3263+
idFieldName = Common.replaceLast(idFieldName, '__r', '__c');
3264+
}
3265+
return idFieldName;
32673266
}
32683267
return fieldName;
32693268
}

test/modules/script/script-object.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,35 @@ describe('Script object external id', () => {
229229
assert.ok(object.query.includes('SobjectType'));
230230
});
231231

232+
it('keeps mixed relationship and local composite externalId fields separated', () => {
233+
const script = new Script();
234+
const object = new ScriptObject('TestObject3__c');
235+
object.externalId = 'TestObject2__r.Name;Test2__c';
236+
object.query = 'SELECT Name, TestObject2__c, Test2__c FROM TestObject3__c';
237+
object.setup(script);
238+
239+
const describe = createDescribe('TestObject3__c', [
240+
{ name: 'Id', type: 'id' },
241+
{ name: 'Name', type: 'string', updateable: true, creatable: true, nameField: true },
242+
{ name: 'Test2__c', type: 'string', updateable: true, creatable: true, custom: true },
243+
{
244+
name: 'TestObject2__c',
245+
type: 'reference',
246+
updateable: true,
247+
creatable: true,
248+
lookup: true,
249+
referencedObjectType: 'TestObject2__c',
250+
custom: true,
251+
},
252+
]);
253+
254+
object.applyDescribe(describe);
255+
256+
assert.ok(object.query.includes('TestObject2__r.Name'));
257+
assert.ok(object.query.includes('Test2__c'));
258+
assert.ok(!object.query.includes('TestObject2__r.Test2__c'));
259+
});
260+
232261
it('recalculates target query after external id change', () => {
233262
const script = new Script();
234263
const object = new ScriptObject('RecordType');

0 commit comments

Comments
 (0)