An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add Relation and Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9888
Danielde73ca8c3b85
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 7f793f2729..261d36f6f7 100644--- a/kernel/av/av.go+++ b/kernel/av/av.go@@ -80,7 +80,7 @@ type Key struct {// 以下是某些列类型的特有属性// 单选/多选列- Options []*KeySelectOption `json:"options,omitempty"` // 选项列表+ Options []*SelectOption `json:"options,omitempty"` // 选项列表// 数字列NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化@@ -114,7 +114,7 @@ type Relation struct {BackKeyID string `json:"backKeyID"` // 双向关联时回链关联列的 ID}-type KeySelectOption struct {+type SelectOption struct {Name string `json:"name"`Color string `json:"color"`}diff --git a/kernel/av/table.go b/kernel/av/table.goindex 71dd16cfd8..d2bb326652 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -651,11 +651,11 @@ type TableColumn struct {// 以下是某些列类型的特有属性- Options []*KeySelectOption `json:"options,omitempty"` // 选项列表- NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化- Template string `json:"template"` // 模板内容- Relation *Relation `json:"relation,omitempty"` // 关联列- Rollup *Rollup `json:"rollup,omitempty"` // 汇总列+ Options []*SelectOption `json:"options,omitempty"` // 选项列表+ NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化+ Template string `json:"template"` // 模板内容+ Relation *Relation `json:"relation,omitempty"` // 关联列+ Rollup *Rollup `json:"rollup,omitempty"` // 汇总列}type TableCell struct {diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 648fc90668..8df88ef346 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -751,6 +751,30 @@ 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+ }++ 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 = ""+ }++ if !isOldSameAv {+ err = av.SaveAttributeView(oldDestAv)+ if nil != err {+ return+ }+ }+ }+ }+keyValues.Key.Relation = &av.Relation{AvID: operation.ID,IsTwoWay: operation.IsTwoWay,@@ -2086,7 +2110,7 @@ func updateAttributeViewColumnOptions(operation *Operation) (err error) {return}- options := []*av.KeySelectOption{}+ options := []*av.SelectOption{}if err = gulu.JSON.UnmarshalJSON(jsonData, &options); nil != err {return}