diff --git a/constants.go b/constants.go index fcf071c..3fe956c 100644 --- a/constants.go +++ b/constants.go @@ -52,4 +52,5 @@ const ( FlagUniqueNameSuffix = "uniqueNameSuffix" FlagUseComments = "comments" FlagUseUTC = "useUTC" + FlagIgnoreUnknownRelation = "ignoreUnknownRelation" ) diff --git a/fmt-jpa.go b/fmt-jpa.go index 456bc6e..1dfa53b 100644 --- a/fmt-jpa.go +++ b/fmt-jpa.go @@ -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) @@ -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 + diff --git a/main.go b/main.go index 4977c7b..0d183e8 100644 --- a/main.go +++ b/main.go @@ -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",