From 8f0fa7bf841bfa27cdaa681a8ec49c8b3bbb37ec Mon Sep 17 00:00:00 2001 From: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Date: Tue, 29 Mar 2022 21:39:49 +0800 Subject: [PATCH] fix translations not using language table name (#12461) --- .../field-detail/store/alterations/translations.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/modules/settings/routes/data-model/field-detail/store/alterations/translations.ts b/app/src/modules/settings/routes/data-model/field-detail/store/alterations/translations.ts index 31889d0783..00511adeed 100644 --- a/app/src/modules/settings/routes/data-model/field-detail/store/alterations/translations.ts +++ b/app/src/modules/settings/routes/data-model/field-detail/store/alterations/translations.ts @@ -18,6 +18,7 @@ export function applyChanges(updates: StateUpdates, state: State, helperFn: Help if (hasChanged('relations.m2o.related_collection')) { preventCircularConstraint(updates, state, helperFn); + updateJunctionRelated(updates, state, helperFn); } if (hasChanged('relations.o2m.field')) { @@ -108,6 +109,16 @@ export function setJunctionFields(updates: StateUpdates, _state: State, { getCur set(updates, 'relations.m2o.meta.junction_field', getCurrent('relations.o2m.field')); } +export function updateJunctionRelated(updates: StateUpdates, _state: State, { getCurrent }: HelperFunctions) { + const fieldsStore = useFieldsStore(); + + const relatedCollection = getCurrent('relations.m2o.related_collection'); + const relatedCollectionPrimaryKeyField = + fieldsStore.getPrimaryKeyFieldForCollection(relatedCollection)?.field ?? 'id'; + + set(updates, 'relations.m2o.field', `${relatedCollection}_${relatedCollectionPrimaryKeyField}`); +} + function collectionExists(collection: string) { return !!useCollectionsStore().getCollection(collection); }