Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888

Daniel4adff64ddc28
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 19961289ca..e92d4ecad2 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -806,38 +806,47 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
}
for _, keyValues := range srcAv.KeyValues {
- if keyValues.Key.ID == operation.KeyID {
- // 已经设置过双向关联的话需要先断开双向关联
- if nil != keyValues.Key.Relation && keyValues.Key.Relation.IsTwoWay {
- oldDestAv, parseErr := av.ParseAttributeView(keyValues.Key.Relation.AvID)
- if nil == parseErr {
- isOldSameAv := oldDestAv.ID == destAv.ID
- if isOldSameAv {
- oldDestAv = destAv
- }
+ if keyValues.Key.ID != operation.KeyID {
+ continue
+ }
- oldDestKey, _ := oldDestAv.GetKey(keyValues.Key.Relation.BackKeyID)
- if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
- oldDestKey.Relation.IsTwoWay = false
- oldDestKey.Relation.BackKeyID = ""
- }
+ srcRel := keyValues.Key.Relation
+ // 已经设置过双向关联的话需要先断开双向关联
+ if nil != srcRel && srcRel.IsTwoWay {
+ oldDestAv, _ := av.ParseAttributeView(srcRel.AvID)
+ if nil != oldDestAv {
+ isOldSameAv := oldDestAv.ID == destAv.ID
+ if isOldSameAv {
+ oldDestAv = destAv
+ }
- if !isOldSameAv {
- err = av.SaveAttributeView(oldDestAv)
- if nil != err {
- return
- }
+ oldDestKey, _ := oldDestAv.GetKey(srcRel.BackKeyID)
+ if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
+ oldDestKey.Relation.IsTwoWay = false
+ oldDestKey.Relation.BackKeyID = ""
+ }
+
+ if !isOldSameAv {
+ err = av.SaveAttributeView(oldDestAv)
+ if nil != err {
+ return
}
}
}
+ }
- keyValues.Key.Relation = &av.Relation{
- AvID: operation.ID,
- IsTwoWay: operation.IsTwoWay,
- BackKeyID: operation.BackRelationKeyID,
- }
- break
+ srcRel = &av.Relation{
+ AvID: operation.ID,
+ IsTwoWay: operation.IsTwoWay,
}
+
+ if operation.IsTwoWay {
+ srcRel.BackKeyID = operation.BackRelationKeyID
+ } else {
+ srcRel.BackKeyID = ""
+ }
+
+ break
}
destAdded := false