diff --git a/kernel/av/av.go b/kernel/av/av.go index 7f793f272..261d36f6f 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.go index 71dd16cfd..d2bb32665 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.go index 648fc9066..8df88ef34 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 }