[feat] add GetModelPrefixForRelations, GetModelJoinsForRelations

This commit is contained in:
what 2023-04-24 13:34:17 +08:00
parent 61b40fef55
commit c0df8cbaff

View File

@ -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
}