ensure update of one_field in m2o (#9708)

This commit is contained in:
Azri Kahar
2021-11-12 04:40:44 +08:00
committed by GitHub
parent bdb00d7ee6
commit 95720bb3f7

View File

@@ -18,6 +18,10 @@ export function applyChanges(updates: StateUpdates, state: State, helperFn: Help
preventCircularConstraint(updates, state);
setTypeToRelatedPrimaryKey(updates, state);
}
if (hasChanged('fields.corresponding')) {
setRelatedOneFieldForCorrespondingField(updates);
}
}
export function prepareRelation(updates: StateUpdates, state: State) {
@@ -99,3 +103,13 @@ export function setTypeToRelatedPrimaryKey(updates: StateUpdates, state: State)
set(updates, 'field.type', state.collections.related.fields[0].type);
}
}
export function setRelatedOneFieldForCorrespondingField(updates: StateUpdates) {
if (updates?.fields?.corresponding?.field) {
set(updates, 'relations.m2o.meta.one_field', updates.fields.corresponding.field);
}
if (!updates.fields?.corresponding) {
set(updates, 'relations.m2o.meta.one_field', null);
}
}