diff --git a/packages/core/core/src/services/document-service/utils/bidirectional-relations.ts b/packages/core/core/src/services/document-service/utils/bidirectional-relations.ts index ababdb52c2..766b72bca8 100644 --- a/packages/core/core/src/services/document-service/utils/bidirectional-relations.ts +++ b/packages/core/core/src/services/document-service/utils/bidirectional-relations.ts @@ -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) => {