Fix translations relationship setup not syncing o2m col to m2o (#10248)

Fixes #9934
This commit is contained in:
Rijk van Zanten
2021-12-02 18:18:40 -05:00
committed by GitHub
parent 3de58431c0
commit 21a053f19a

View File

@@ -28,6 +28,10 @@ export function applyChanges(updates: StateUpdates, state: State, helperFn: Help
setJunctionFields(updates, state, helperFn);
}
if (hasChanged('relations.o2m.collection') || hasChanged('relations.m2o.collection')) {
matchJunctionCollectionName(updates);
}
if (
[
'relations.o2m.collection',
@@ -292,6 +296,16 @@ export function setDefaults(updates: StateUpdates, state: State, { getCurrent }:
}
}
export function matchJunctionCollectionName(updates: StateUpdates) {
if (updates?.relations?.o2m?.collection && updates.relations.o2m.collection !== updates.relations.m2o?.collection) {
set(updates, 'relations.m2o.collection', updates.relations.o2m.collection);
}
if (updates?.relations?.m2o?.collection && updates.relations.m2o.collection !== updates.relations.o2m?.collection) {
set(updates, 'relations.o2m.collection', updates.relations.m2o.collection);
}
}
export function getAutomaticJunctionCollectionName(collectionA: string) {
let index = 0;
let name = getName(index);