Skip to content

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

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

Daniel87096f96712e
diff --git a/kernel/av/av.go b/kernel/av/av.go
index a85a3766d6..0767c850c5 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -90,7 +90,6 @@ type Key struct {
// 关联列
RelationAvID string `json:"relationAvID"` // 关联的属性视图 ID
- RelationKeyID string `json:"relationKeyID"` // 关联列 ID
IsBiRelation bool `json:"isBiRelation"` // 是否双向关联
BackRelationKeyID string `json:"backRelationKeyID"` // 双向关联时回链关联列的 ID
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 93cc157fb3..0c143f8447 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -655,6 +655,44 @@ func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
return
}
+func (tx *Transaction) doUpdateAttrViewColRelation(operation *Operation) (ret *TxErr) {
+ err := updateAttributeViewColRelation(operation)
+ if nil != err {
+ return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
+ }
+ return
+}
+
+func updateAttributeViewColRelation(operation *Operation) (err error) {
+ err = updateAttributeViewColRelation0(operation.AvID, operation.KeyID, operation.ID, operation.IsBiRelation, operation.BackRelationKeyID)
+ if nil != err {
+ return
+ }
+
+ if operation.IsBiRelation {
+ err = updateAttributeViewColRelation0(operation.ID, operation.BackRelationKeyID, operation.AvID, operation.IsBiRelation, operation.KeyID)
+ }
+ return
+}
+
+func updateAttributeViewColRelation0(avID, relKeyID, destAvID string, isBiRel bool, backRelKeyID string) (err error) {
+ attrView, err := av.ParseAttributeView(avID)
+ if nil != err {
+ return
+ }
+
+ for _, keyValues := range attrView.KeyValues {
+ if keyValues.Key.ID == relKeyID {
+ keyValues.Key.RelationAvID = destAvID
+ keyValues.Key.IsBiRelation = isBiRel
+ keyValues.Key.BackRelationKeyID = backRelKeyID
+ err = av.SaveAttributeView(attrView)
+ return
+ }
+ }
+ return
+}
+
func (tx *Transaction) doSortAttrViewView(operation *Operation) (ret *TxErr) {
avID := operation.AvID
attrView, err := av.ParseAttributeView(avID)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 352d1b03ee..3647eb77d9 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -258,6 +258,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doDuplicateAttrViewView(op)
case "sortAttrViewView":
ret = tx.doSortAttrViewView(op)
+ case "updateAttrViewColRelation":
+ ret = tx.doUpdateAttrViewColRelation(op)
}
if nil != ret {
@@ -1181,14 +1183,16 @@ type Operation struct {
DeckID string `json:"deckID"` // 用于添加/删除闪卡
- AvID string `json:"avID"` // 属性视图 ID
- SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
- IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
- Name string `json:"name"` // 属性视图列名
- Typ string `json:"type"` // 属性视图列类型
- Format string `json:"format"` // 属性视图列格式化
- KeyID string `json:"keyID"` // 属性视列 ID
- RowID string `json:"rowID"` // 属性视图行 ID
+ AvID string `json:"avID"` // 属性视图 ID
+ SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
+ IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
+ Name string `json:"name"` // 属性视图列名
+ Typ string `json:"type"` // 属性视图列类型
+ Format string `json:"format"` // 属性视图列格式化
+ KeyID string `json:"keyID"` // 属性视列 ID
+ RowID string `json:"rowID"` // 属性视图行 ID
+ IsBiRelation bool `json:"isBiRelation"` // 属性视图关联列是否是双向关系
+ BackRelationKeyID string `json:"backRelationKeyID"` // 属性视图关联列回链关联列的 ID
}
type Transaction struct {