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

Daniel940dff4c7f89
diff --git a/kernel/av/table.go b/kernel/av/table.go
index 69b161efec..50f47e4d6a 100644
--- a/kernel/av/table.go
+++ b/kernel/av/table.go
@@ -591,19 +591,31 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
if nil != value.Relation && nil != other.Relation {
switch operator {
case FilterOperatorContains:
- if "" == strings.TrimSpace(other.Relation.Content) {
- return true
+ contains := false
+ for _, c := range value.Relation.Contents {
+ for _, c1 := range other.Relation.Contents {
+ if c == c1 {
+ contains = true
+ break
+ }
+ }
}
- return strings.Contains(value.Relation.Content, other.Relation.Content)
+ return contains
case FilterOperatorDoesNotContain:
- if "" == strings.TrimSpace(other.Relation.Content) {
- return true
+ contains := false
+ for _, c := range value.Relation.Contents {
+ for _, c2 := range other.Relation.Contents {
+ if c == c2 {
+ contains = true
+ break
+ }
+ }
}
- return !strings.Contains(value.Relation.Content, other.Relation.Content)
+ return !contains
case FilterOperatorIsEmpty:
- return "" == strings.TrimSpace(value.Relation.Content)
+ return 0 == len(value.Relation.Contents) || 1 == len(value.Relation.Contents) && "" == value.Relation.Contents[0]
case FilterOperatorIsNotEmpty:
- return "" != strings.TrimSpace(value.Relation.Content)
+ return 0 != len(value.Relation.Contents) && !(1 == len(value.Relation.Contents) && "" == value.Relation.Contents[0])
}
}
diff --git a/kernel/av/value.go b/kernel/av/value.go
index d3f0cac445..73015cbda9 100644
--- a/kernel/av/value.go
+++ b/kernel/av/value.go
@@ -142,10 +142,14 @@ func (value *Value) String() string {
}
return ""
case KeyTypeRelation:
- if nil == value.Relation {
+ if 1 > len(value.Relation.Contents) {
return ""
}
- return value.Relation.Content
+ var ret []string
+ for _, v := range value.Relation.Contents {
+ ret = append(ret, v)
+ }
+ return strings.Join(ret, " ")
case KeyTypeRollup:
if nil == value.Rollup {
return ""
@@ -463,7 +467,7 @@ type ValueCheckbox struct {
}
type ValueRelation struct {
- Content string `json:"content"`
+ Contents []string `json:"contents"`
BlockIDs []string `json:"blockIDs"`
}