Skip to content

Commit

Permalink
Merge pull request #32 from sinna94/relation
Browse files Browse the repository at this point in the history
fix relation in fmt-jpa.go
  • Loading branch information
lechuckroh committed Oct 16, 2020
2 parents 7ea3e0a + f63ce21 commit ea0bcc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ const (
FlagUniqueNameSuffix = "uniqueNameSuffix"
FlagUseComments = "comments"
FlagUseUTC = "useUTC"
FlagIgnoreUnknownRelation = "ignoreUnknownRelation"
)
16 changes: 15 additions & 1 deletion fmt-jpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (k *JPAKotlin) Generate(
reposPackage := output.Get(FlagReposPackage)
graphqlPackage := output.Get(FlagGraphqlPackage)
relation := output.Get(FlagRelation)
ignoreUnknownRelation := output.Get(FlagIgnoreUnknownRelation)
uniqueNameSuffix := output.Get(FlagUniqueNameSuffix)
idEntityInterfaceName := output.Get(FlagIdEntity)

Expand Down Expand Up @@ -318,7 +319,20 @@ func (k *JPAKotlin) Generate(
if ref := column.Ref; ref != nil {
targetClassName := getClassNameByTable(ref.Table)
if len(targetClassName) == 0 {
log.Fatalf("Relation not found. %s::%s -> %s", class.Name, field.Name, ref.Table)
if ignoreUnknownRelation == "true"{
log.Printf("Relation not found. %s::%s -> %s\n", class.Name, field.Name, ref.Table)
appendLine(indent +
fmt.Sprintf("@VRelation(cls = \"%s\", field = \"%s\")",
strcase.ToCamel(ref.Table),
strcase.ToLowerCamel(ref.Column)))
}else{
log.Fatalf("Relation not found. %s::%s -> %s\n", class.Name, field.Name, ref.Table)
}
} else {
appendLine(indent +
fmt.Sprintf("@VRelation(cls = \"%s\", field = \"%s\")",
targetClassName,
strcase.ToLowerCamel(ref.Column)))
}

appendLine(indent +
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ func main() {
Usage: "set relation annotation type",
EnvVar: "OCTOPUS_RELATION",
},
cli.StringFlag{
Name: FlagIgnoreUnknownRelation,
Usage: "ignore unknown relation",
EnvVar: "OCTOPUS_IGNORE_UNKNOWN_RELATION",
},
cli.StringFlag{
Name: FlagAnnotation,
Usage: "add custom class annotations",
Expand Down

0 comments on commit ea0bcc6

Please sign in to comment.