From c0df8cbaffa98bc9855fb63a8ca33c1dd7cd7da3 Mon Sep 17 00:00:00 2001 From: what Date: Mon, 24 Apr 2023 13:34:17 +0800 Subject: [PATCH] [feat] add GetModelPrefixForRelations, GetModelJoinsForRelations --- base/res_relation.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/base/res_relation.go b/base/res_relation.go index c2f9faa..61a158d 100644 --- a/base/res_relation.go +++ b/base/res_relation.go @@ -49,3 +49,26 @@ func GetJoinResDependencies(root string, items []ResRelation) (dependencies []st return dependencies } + +func GetModelPrefixForRelations(model string, items []ResRelation) (result []any) { + result = append([]any{model}, result...) + for _, item := range items { + if item.Code == model && (item.Type == "hasMany" || item.Type == "hasOne") { + if item.Type == "hasMany" { + result = append(result, 0) + } + return append(GetModelPrefixForRelations(item.RelationResource, items), result...) + } + } + return result +} + +func GetModelJoinsForRelations(model string, items []ResRelation) (result []string) { + result = append([]string{model}, result...) + for _, item := range items { + if item.Code == model && (item.Type == "left" || item.Type == "right" || item.Type == "inner") { + return append(GetModelJoinsForRelations(item.RelationResource, items), result...) + } + } + return result +}