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); }