Skip to content

Commit

Permalink
add flag to ignore unknown relation
Browse files Browse the repository at this point in the history
  • Loading branch information
이충현 committed Oct 16, 2020
1 parent 9b4c5fc commit f63ce21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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"
)
15 changes: 10 additions & 5 deletions 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,11 +319,15 @@ func (k *JPAKotlin) Generate(
if ref := column.Ref; ref != nil {
targetClassName := getClassNameByTable(ref.Table)
if len(targetClassName) == 0 {
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)))
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\")",
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 f63ce21

Please sign in to comment.