fix: bidirectional relations sync

This commit is contained in:
Marc-Roig 2025-03-12 11:30:36 +01:00 committed by Alexandre Bodin
parent b87e54e6fd
commit ad216ff22f

View File

@ -73,6 +73,11 @@ const load = async (uid: UID.ContentType, { oldVersions }: LoadContext) => {
continue;
}
// If it's a self referencing relation, there is no need to sync any relation
if (model.uid === uid) {
continue;
}
const joinTable = attribute.joinTable;
if (!joinTable) {
continue;
@ -151,6 +156,11 @@ const sync = async (
const targetColumn = joinTable.joinColumn.name;
const orderColumn = joinTable.orderColumnName;
// Failsafe in case those don't exist
if (!sourceColumn || !targetColumn || !orderColumn) {
continue;
}
// Update order values for each relation
// TODO: Find a way to batch it more efficiently
await async.map(relations, (relation: any) => {