Skip to content

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

:art: Improve interaction when deleting two-way relation field in a database https://github.com/siyuan-note/siyuan/issues/11252

Danielf12910e7609a
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index c5b4ed602c..f207e1f726 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -2796,27 +2796,35 @@ func RemoveAttributeViewKey(avID, keyID string, removeRelationDest bool) (err er
if nil != removedKey && av.KeyTypeRelation == removedKey.Type && nil != removedKey.Relation {
if removedKey.Relation.IsTwoWay {
- if removeRelationDest { // 删除双向关联的目标列
- var destAv *av.AttributeView
- if avID == removedKey.Relation.AvID {
- destAv = attrView
- } else {
- destAv, _ = av.ParseAttributeView(removedKey.Relation.AvID)
+ var destAv *av.AttributeView
+ if avID == removedKey.Relation.AvID {
+ destAv = attrView
+ } else {
+ destAv, _ = av.ParseAttributeView(removedKey.Relation.AvID)
+ }
+
+ if nil != destAv {
+ oldDestKey, _ := destAv.GetKey(removedKey.Relation.BackKeyID)
+ if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == attrView.ID && oldDestKey.Relation.IsTwoWay {
+ oldDestKey.Relation.IsTwoWay = false
+ oldDestKey.Relation.BackKeyID = ""
}
- if nil != destAv {
- destAvRelSrcAv := false
- for i, keyValues := range destAv.KeyValues {
- if keyValues.Key.ID == removedKey.Relation.BackKeyID {
+ destAvRelSrcAv := false
+ for i, keyValues := range destAv.KeyValues {
+ if keyValues.Key.ID == removedKey.Relation.BackKeyID {
+ if removeRelationDest { // 删除双向关联的目标列
destAv.KeyValues = append(destAv.KeyValues[:i], destAv.KeyValues[i+1:]...)
- continue
}
+ continue
+ }
- if av.KeyTypeRelation == keyValues.Key.Type && keyValues.Key.Relation.AvID == attrView.ID {
- destAvRelSrcAv = true
- }
+ if av.KeyTypeRelation == keyValues.Key.Type && keyValues.Key.Relation.AvID == attrView.ID {
+ destAvRelSrcAv = true
}
+ }
+ if removeRelationDest {
for _, view := range destAv.Views {
switch view.LayoutType {
case av.LayoutTypeTable:
@@ -2828,15 +2836,15 @@ func RemoveAttributeViewKey(avID, keyID string, removeRelationDest bool) (err er
}
}
}
+ }
- if destAv != attrView {
- av.SaveAttributeView(destAv)
- ReloadAttrView(destAv.ID)
- }
+ if destAv != attrView {
+ av.SaveAttributeView(destAv)
+ ReloadAttrView(destAv.ID)
+ }
- if !destAvRelSrcAv {
- av.RemoveAvRel(destAv.ID, attrView.ID)
- }
+ if !destAvRelSrcAv {
+ av.RemoveAvRel(destAv.ID, attrView.ID)
}
}