Skip to content

Commit 92180c2

Browse files
committed
fix: avoid exact relation being redeclared
1 parent 6243b68 commit 92180c2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/generator/model.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package generator
33
import (
44
"fmt"
55
"path/filepath"
6+
"reflect"
67
"sort"
78
"strings"
89
"text/template"
@@ -252,6 +253,16 @@ func buildColumnTag(c objects.Column, mapPk map[string]bool, validationTags stat
252253
return strings.Join(tags, " ")
253254
}
254255

256+
func containsRelation(relations []state.Relation, r state.Relation) bool {
257+
for _, rel := range relations {
258+
if reflect.DeepEqual(rel, r) {
259+
return true
260+
}
261+
}
262+
263+
return false
264+
}
265+
255266
func BuildJoinTag(r *state.Relation) string {
256267
var tags []string
257268
var joinTags []string
@@ -337,7 +348,10 @@ func BuildRelationFields(table objects.Table, relations []state.Relation) (mappe
337348
}
338349

339350
r.Tag = BuildJoinTag(&r)
340-
mappedRelations = append(mappedRelations, r)
351+
352+
if !containsRelation(mappedRelations, r) {
353+
mappedRelations = append(mappedRelations, r)
354+
}
341355
}
342356

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

0 commit comments

Comments
 (0)