Skip to content

Commit

Permalink
Merge pull request #115 from stephenafamo/fix/112-join-alias
Browse files Browse the repository at this point in the history
correctly use table alias in join query
  • Loading branch information
stephenafamo authored Oct 14, 2023
2 parents ead0ba4 + c18d2bc commit dbbbcbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gen/bobgen-psql/driver/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Config struct {
// The name of this schema will not be included in the generated models
// a context value can then be used to set the schema at runtime
// useful for multi-tenant setups
SharedSchema string
SharedSchema string `yaml:"shared_schema"`
// List of tables that will be included. Others are ignored
Only map[string][]string
// List of tables that will be should be ignored. Others are included
Expand Down
6 changes: 3 additions & 3 deletions gen/templates/models/09_rel_query.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func {{$tAlias.DownPlural}}Join{{$relAlias}}[Q dialect.Joinable](ctx context.Con
{{- $from := $.Aliases.Table $side.From -}}
{{- $to := $.Aliases.Table $side.To -}}
{{- $toTable := getTable $.Tables $side.To -}}
dialect.Join[Q](typ, {{$to.UpPlural}}.Name(ctx)).On(
dialect.Join[Q](typ, {{$to.UpPlural}}.NameAs(ctx)).On(
{{range $i, $local := $side.FromColumns -}}
{{- $fromCol := index $from.Columns $local -}}
{{- $toCol := index $to.Columns (index $side.ToColumns $i) -}}
Expand Down Expand Up @@ -50,7 +50,7 @@ func (o *{{$tAlias.UpSingular}}) {{relQueryMethodName $tAlias $relAlias}}(ctx co
{{- $to := $.Aliases.Table $side.To -}}
{{- $fromTable := getTable $.Tables $side.From -}}
{{- if gt $index 0 -}}
sm.InnerJoin({{$from.UpPlural}}.Name(ctx)).On(
sm.InnerJoin({{$from.UpPlural}}.NameAs(ctx)).On(
{{end -}}
{{range $i, $local := $side.FromColumns -}}
{{- $fromCol := index $from.Columns $local -}}
Expand Down Expand Up @@ -110,7 +110,7 @@ func (os {{$tAlias.UpSingular}}Slice) {{relQueryMethodName $tAlias $relAlias}}(c
{{- $to := $.Aliases.Table $side.To -}}
{{- $fromTable := getTable $.Tables $side.From -}}
{{- if gt $index 0 -}}
sm.InnerJoin({{$from.UpPlural}}.Name(ctx)).On(
sm.InnerJoin({{$from.UpPlural}}.NameAs(ctx)).On(
{{range $i, $local := $side.FromColumns -}}
{{- $foreign := index $side.ToColumns $i -}}
{{- $fromCol := index $from.Columns $local -}}
Expand Down

0 comments on commit dbbbcbe

Please sign in to comment.