Skip to content

Commit 47521a4

Browse files
committed
refactor: use column names instead of * for eager loading in m2m relationships
As stated in volatiletech#809, the order of columns may cause errors during eager loading. This commits only replaces `select *` in m2m relationships eager loading with actual column names, since this is the only place eager loaded data is scanned manually with generated code.
1 parent d551047 commit 47521a4

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

drivers/sqlboiler-mssql/driver/bindata.go

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drivers/sqlboiler-psql/driver/bindata.go

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templatebin/bindata.go

+8-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/09_relationship_to_many_eager.go.tpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ func ({{$ltable.DownSingular}}L) Load{{$relAlias.Local}}({{if $.NoContext}}e boi
5555

5656
{{if .ToJoinTable -}}
5757
{{- $schemaJoinTable := .JoinTable | $.SchemaTable -}}
58+
{{- $foreignTable := getTable $.Tables .ForeignTable -}}
5859
query := NewQuery(
59-
qm.Select("{{$schemaForeignTable}}.*, {{id 0 | $.Quotes}}.{{.JoinLocalColumn | $.Quotes}}"),
60+
qm.Select("{{$foreignTable.Columns | columnNames | prefixStringSlice (print $schemaForeignTable ".") | join ", "}}, {{id 0 | $.Quotes}}.{{.JoinLocalColumn | $.Quotes}}"),
6061
qm.From("{{$schemaForeignTable}}"),
6162
qm.InnerJoin("{{$schemaJoinTable}} as {{id 0 | $.Quotes}} on {{$schemaForeignTable}}.{{.ForeignColumn | $.Quotes}} = {{id 0 | $.Quotes}}.{{.JoinForeignColumn | $.Quotes}}"),
6263
qm.WhereIn("{{id 0 | $.Quotes}}.{{.JoinLocalColumn | $.Quotes}} in ?", args...),

0 commit comments

Comments
 (0)