From c18d2bc57e6475add7dd4058ec49a87d1d5d2f57 Mon Sep 17 00:00:00 2001 From: Stephen Afam-Osemene Date: Sat, 14 Oct 2023 10:09:30 +0100 Subject: [PATCH] correctly use table alias in join query --- gen/bobgen-psql/driver/psql.go | 2 +- gen/templates/models/09_rel_query.go.tpl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gen/bobgen-psql/driver/psql.go b/gen/bobgen-psql/driver/psql.go index d27e1d2a..a49ad72d 100644 --- a/gen/bobgen-psql/driver/psql.go +++ b/gen/bobgen-psql/driver/psql.go @@ -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 diff --git a/gen/templates/models/09_rel_query.go.tpl b/gen/templates/models/09_rel_query.go.tpl index 94b14ba6..e29f1f97 100644 --- a/gen/templates/models/09_rel_query.go.tpl +++ b/gen/templates/models/09_rel_query.go.tpl @@ -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) -}} @@ -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 -}} @@ -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 -}}