Ver Fonte

:art: Improve database handling when importing .sy.zip https://github.com/siyuan-note/siyuan/issues/11628

Daniel há 1 ano atrás
pai
commit
cf5ff5283a
1 ficheiros alterados com 19 adições e 0 exclusões
  1. 19 0
      kernel/model/import.go

+ 19 - 0
kernel/model/import.go

@@ -312,6 +312,25 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
 			attrViewIDs = append(attrViewIDs, avID)
 		}
 		updateBoundBlockAvsAttribute(attrViewIDs)
+
+		// 插入关联关系 https://github.com/siyuan-note/siyuan/issues/11628
+		relationAvs := map[string]string{}
+		for _, avID := range avIDs {
+			attrView, _ := av.ParseAttributeView(avID)
+			if nil == attrView {
+				continue
+			}
+
+			for _, keyValues := range attrView.KeyValues {
+				if nil != keyValues.Key && av.KeyTypeRelation == keyValues.Key.Type && nil != keyValues.Key.Relation {
+					relationAvs[avID] = keyValues.Key.Relation.AvID
+				}
+			}
+		}
+
+		for srcAvID, destAvID := range relationAvs {
+			av.UpsertAvBackRel(srcAvID, destAvID)
+		}
 	}
 
 	// 将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中