Skip to content

Commit 32b28b7

Browse files
fix(core): Persist scalar custom fields in updateGlobalSettings with relations
Save the entity to DB before calling updateRelations so that when updateRelations re-fetches the entity, it picks up the already-persisted scalar custom field values instead of stale DB values. Fixes #4342 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fbd4202 commit 32b28b7

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

packages/core/e2e/custom-field-relations.e2e-spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,37 @@ describe('Custom field relations', () => {
710710
`);
711711
assertCustomFieldIds(updateGlobalSettings.customFields, 'T_2', ['T_3', 'T_4']);
712712
});
713+
714+
// https://github.com/vendurehq/vendure/issues/4342
715+
it('scalar custom fields persist when updating alongside relations', async () => {
716+
const { updateGlobalSettings } = await adminClient.query(gql`
717+
mutation {
718+
updateGlobalSettings(
719+
input: {
720+
customFields: { primitive: "updated", singleId: "T_3", multiIds: ["T_1", "T_2"] }
721+
}
722+
) {
723+
... on GlobalSettings {
724+
id
725+
${customFieldsSelection}
726+
}
727+
}
728+
}
729+
`);
730+
expect(updateGlobalSettings.customFields.primitive).toBe('updated');
731+
assertCustomFieldIds(updateGlobalSettings.customFields, 'T_3', ['T_1', 'T_2']);
732+
733+
// Verify the scalar value actually persisted by re-querying
734+
const { globalSettings } = await adminClient.query(gql`
735+
query {
736+
globalSettings {
737+
${customFieldsSelection}
738+
}
739+
}
740+
`);
741+
expect(globalSettings.customFields.primitive).toBe('updated');
742+
assertCustomFieldIds(globalSettings.customFields, 'T_3', ['T_1', 'T_2']);
743+
});
713744
});
714745

715746
describe('Order entity', () => {

packages/core/src/service/services/global-settings.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export class GlobalSettingsService {
7878
const settings = await this.getSettings(ctx);
7979
await this.eventBus.publish(new GlobalSettingsEvent(ctx, settings, input));
8080
patchEntity(settings, input);
81-
await this.customFieldRelationService.updateRelations(ctx, GlobalSettings, input, settings);
82-
return this.connection.getRepository(ctx, GlobalSettings).save(settings);
81+
const savedSettings = await this.connection.getRepository(ctx, GlobalSettings).save(settings);
82+
await this.customFieldRelationService.updateRelations(ctx, GlobalSettings, input, savedSettings);
83+
return savedSettings;
8384
}
8485
}

0 commit comments

Comments
 (0)