mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 23:50:13 +01:00
🎨 Synchronize the related entries when the database creates a two-way relation https://github.com/siyuan-note/siyuan/issues/11250
This commit is contained in:
parent
ce47fd2ed4
commit
bf4b9cf146
1 changed files with 85 additions and 67 deletions
|
|
@ -1577,21 +1577,22 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !destAdded {
|
if !destAdded && operation.IsTwoWay {
|
||||||
if operation.IsTwoWay {
|
// 新建双向关联目标字段
|
||||||
name := strings.TrimSpace(operation.Name)
|
name := strings.TrimSpace(operation.Name)
|
||||||
if "" == name {
|
if "" == name {
|
||||||
name = srcAv.Name + " " + operation.Format
|
name = srcAv.Name + " " + operation.Format
|
||||||
}
|
}
|
||||||
|
|
||||||
destAv.KeyValues = append(destAv.KeyValues, &av.KeyValues{
|
destKeyValues := &av.KeyValues{
|
||||||
Key: &av.Key{
|
Key: &av.Key{
|
||||||
ID: operation.BackRelationKeyID,
|
ID: operation.BackRelationKeyID,
|
||||||
Name: name,
|
Name: name,
|
||||||
Type: av.KeyTypeRelation,
|
Type: av.KeyTypeRelation,
|
||||||
Relation: &av.Relation{AvID: operation.AvID, IsTwoWay: operation.IsTwoWay, BackKeyID: operation.KeyID},
|
Relation: &av.Relation{AvID: operation.AvID, IsTwoWay: operation.IsTwoWay, BackKeyID: operation.KeyID},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
destAv.KeyValues = append(destAv.KeyValues, destKeyValues)
|
||||||
|
|
||||||
for _, v := range destAv.Views {
|
for _, v := range destAv.Views {
|
||||||
switch v.LayoutType {
|
switch v.LayoutType {
|
||||||
|
|
@ -1599,6 +1600,24 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||||
v.Table.Columns = append(v.Table.Columns, &av.ViewTableColumn{ID: operation.BackRelationKeyID})
|
v.Table.Columns = append(v.Table.Columns, &av.ViewTableColumn{ID: operation.BackRelationKeyID})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now().UnixMilli()
|
||||||
|
// 和现有值进行关联
|
||||||
|
for _, keyValues := range srcAv.KeyValues {
|
||||||
|
if keyValues.Key.ID != operation.KeyID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
srcKeyValues := keyValues
|
||||||
|
for _, srcVal := range srcKeyValues.Values {
|
||||||
|
for _, blockID := range srcVal.Relation.BlockIDs {
|
||||||
|
destVal := &av.Value{ID: ast.NewNodeID(), KeyID: destKeyValues.Key.ID, BlockID: blockID, Type: keyValues.Key.Type, Relation: &av.ValueRelation{}}
|
||||||
|
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
|
||||||
|
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
|
||||||
|
destVal.SetUpdatedAt(now)
|
||||||
|
destKeyValues.Values = append(destKeyValues.Values, destVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3195,10 +3214,10 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
|
||||||
val.SetUpdatedAt(now)
|
val.SetUpdatedAt(now)
|
||||||
|
|
||||||
key, _ := attrView.GetKey(val.KeyID)
|
key, _ := attrView.GetKey(val.KeyID)
|
||||||
if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation {
|
if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation && key.Relation.IsTwoWay {
|
||||||
destAv, _ := av.ParseAttributeView(key.Relation.AvID)
|
// 双向关联需要同时更新目标字段的值
|
||||||
if nil != destAv {
|
|
||||||
if key.Relation.IsTwoWay {
|
if destAv, _ := av.ParseAttributeView(key.Relation.AvID); nil != destAv {
|
||||||
// relationChangeMode
|
// relationChangeMode
|
||||||
// 0:关联列值不变(仅排序),不影响目标值
|
// 0:关联列值不变(仅排序),不影响目标值
|
||||||
// 1:关联列值增加,增加目标值
|
// 1:关联列值增加,增加目标值
|
||||||
|
|
@ -3254,7 +3273,6 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
|
||||||
av.SaveAttributeView(destAv)
|
av.SaveAttributeView(destAv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
relatedAvIDs := av.GetSrcAvIDs(avID)
|
relatedAvIDs := av.GetSrcAvIDs(avID)
|
||||||
for _, relatedAvID := range relatedAvIDs {
|
for _, relatedAvID := range relatedAvIDs {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue