🎨 Improve interaction when deleting two-way relation field in a database https://github.com/siyuan-note/siyuan/issues/11252
This commit is contained in:
parent
f5615c10b7
commit
f12910e760
1 changed files with 30 additions and 22 deletions
|
@ -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
|
||||
}
|
||||
|
||||
if av.KeyTypeRelation == keyValues.Key.Type && keyValues.Key.Relation.AvID == attrView.ID {
|
||||
destAvRelSrcAv = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue