Skip to content

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

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

Daniel4e8d045452a6
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 11c7346095..9767722aaf 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -183,6 +183,20 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
// 先处理创建时间和更新时间
for _, kv := range keyValues {
switch kv.Key.Type {
+ case av.KeyTypeRelation:
+ relKey, _ := attrView.GetKey(kv.Values[0].KeyID)
+ if nil != relKey && nil != relKey.Relation {
+ destAv, _ := av.ParseAttributeView(relKey.Relation.AvID)
+ if nil != destAv {
+ blocks := map[string]string{}
+ for _, blockValue := range destAv.GetBlockKeyValues().Values {
+ blocks[blockValue.BlockID] = blockValue.Block.Content
+ }
+ for _, blockID := range kv.Values[0].Relation.BlockIDs {
+ kv.Values[0].Relation.Contents = append(kv.Values[0].Relation.Contents, blocks[blockID])
+ }
+ }
+ }
case av.KeyTypeCreated:
createdStr := blockID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
@@ -686,10 +700,19 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
cell.Value.Template.Content = content
case av.KeyTypeRelation: // 渲染关联列
-
- //for _, blockID := range cell.Value.Relation.BlockIDs {
- //
- //}
+ relKey, _ := attrView.GetKey(cell.Value.KeyID)
+ if nil != relKey && nil != relKey.Relation {
+ destAv, _ := av.ParseAttributeView(relKey.Relation.AvID)
+ if nil != destAv {
+ blocks := map[string]string{}
+ for _, blockValue := range destAv.GetBlockKeyValues().Values {
+ blocks[blockValue.BlockID] = blockValue.Block.Content
+ }
+ for _, blockID := range cell.Value.Relation.BlockIDs {
+ cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID])
+ }
+ }
+ }
case av.KeyTypeCreated: // 渲染创建时间
createdStr := row.ID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go
index f153057442..82ef223c0a 100644
--- a/kernel/treenode/node.go
+++ b/kernel/treenode/node.go
@@ -724,6 +724,20 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
}
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
cell.Value.Template.Content = content
+ case av.KeyTypeRelation: // 渲染关联列
+ relKey, _ := attrView.GetKey(cell.Value.KeyID)
+ if nil != relKey && nil != relKey.Relation {
+ destAv, _ := av.ParseAttributeView(relKey.Relation.AvID)
+ if nil != destAv {
+ blocks := map[string]string{}
+ for _, blockValue := range destAv.GetBlockKeyValues().Values {
+ blocks[blockValue.BlockID] = blockValue.Block.Content
+ }
+ for _, blockID := range cell.Value.Relation.BlockIDs {
+ cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID])
+ }
+ }
+ }
case av.KeyTypeCreated: // 渲染创建时间
createdStr := row.ID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)