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

This commit is contained in:
Daniel 2023-12-24 11:24:40 +08:00
parent 67af0fbe9a
commit 4adff64ddc
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017

View File

@ -806,38 +806,47 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
} }
for _, keyValues := range srcAv.KeyValues { for _, keyValues := range srcAv.KeyValues {
if keyValues.Key.ID == operation.KeyID { if keyValues.Key.ID != operation.KeyID {
// 已经设置过双向关联的话需要先断开双向关联 continue
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
}
oldDestKey, _ := oldDestAv.GetKey(keyValues.Key.Relation.BackKeyID) srcRel := keyValues.Key.Relation
if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay { // 已经设置过双向关联的话需要先断开双向关联
oldDestKey.Relation.IsTwoWay = false if nil != srcRel && srcRel.IsTwoWay {
oldDestKey.Relation.BackKeyID = "" oldDestAv, _ := av.ParseAttributeView(srcRel.AvID)
} if nil != oldDestAv {
isOldSameAv := oldDestAv.ID == destAv.ID
if isOldSameAv {
oldDestAv = destAv
}
if !isOldSameAv { oldDestKey, _ := oldDestAv.GetKey(srcRel.BackKeyID)
err = av.SaveAttributeView(oldDestAv) if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
if nil != err { oldDestKey.Relation.IsTwoWay = false
return 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 destAdded := false