From 848289ef5456babe0a21132d279b62c29b2a27df Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 24 Dec 2023 14:40:05 +0800 Subject: [PATCH] :art: Add Relation column to database table view https://github.com/siyuan-note/siyuan/issues/9888 --- kernel/model/attribute_view.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index d165e0534..53d8024dc 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -18,6 +18,7 @@ package model import ( "bytes" + "errors" "os" "path/filepath" "sort" @@ -790,6 +791,11 @@ func updateAttributeViewColRelation(operation *Operation) (err error) { // operation.BackRelationKeyID 双向关联的目标关联列 ID // operation.Name 双向关联的目标关联列名称 + if "" == operation.AvID || "" == operation.ID || "" == operation.KeyID { + err = errors.New("invalid operation") + return + } + srcAv, err := av.ParseAttributeView(operation.AvID) if nil != err { return @@ -862,10 +868,15 @@ func updateAttributeViewColRelation(operation *Operation) (err error) { if !destAdded { if operation.IsTwoWay { + name := strings.TrimSpace(operation.Name) + if "" == name { + name = destAv.Name + } + destAv.KeyValues = append(destAv.KeyValues, &av.KeyValues{ Key: &av.Key{ ID: operation.BackRelationKeyID, - Name: operation.Name, + Name: name, Type: av.KeyTypeRelation, Relation: &av.Relation{AvID: operation.AvID, IsTwoWay: operation.IsTwoWay, BackKeyID: operation.KeyID}, },