Skip to content

Commit

Permalink
fix: avoid exact relation being redeclared
Browse files Browse the repository at this point in the history
  • Loading branch information
toopay committed Sep 8, 2024
1 parent 6243b68 commit 92180c2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/generator/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generator
import (
"fmt"
"path/filepath"
"reflect"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -252,6 +253,16 @@ func buildColumnTag(c objects.Column, mapPk map[string]bool, validationTags stat
return strings.Join(tags, " ")
}

func containsRelation(relations []state.Relation, r state.Relation) bool {
for _, rel := range relations {
if reflect.DeepEqual(rel, r) {
return true
}
}

return false
}

func BuildJoinTag(r *state.Relation) string {
var tags []string
var joinTags []string
Expand Down Expand Up @@ -337,7 +348,10 @@ func BuildRelationFields(table objects.Table, relations []state.Relation) (mappe
}

r.Tag = BuildJoinTag(&r)
mappedRelations = append(mappedRelations, r)

if !containsRelation(mappedRelations, r) {
mappedRelations = append(mappedRelations, r)
}
}

sort.Slice(mappedRelations, func(i, j int) bool {
Expand Down

0 comments on commit 92180c2

Please sign in to comment.