Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions boil/load_map_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package boil

import (
"github.com/volatiletech/null/v8"
)

func GenLoadMapKey(key interface{}) interface{} {
switch t := key.(type) {
case []byte:
return string(t)
case null.Bytes:
return string(t.Bytes)
default:
return key
}

}
12 changes: 6 additions & 6 deletions templates/main/07_relationship_to_one_eager.go.tpl
Original file line number Diff line number Diff line change
@@ -37,16 +37,16 @@ func ({{$ltable.DownSingular}}L) Load{{$rel.Foreign}}({{if $.NoContext}}e boil.E
}
}

args := make(map[interface{}]struct{})
args := make(map[interface{}]interface{})
if singular {
if object.R == nil {
object.R = &{{$ltable.DownSingular}}R{}
}
{{if $usesPrimitives -}}
args[object.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(object.{{$col}})] = object.{{$col}}
{{else -}}
if !queries.IsNil(object.{{$col}}) {
args[object.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(object.{{$col}})] = object.{{$col}}
}
{{end}}
} else {
@@ -56,10 +56,10 @@ func ({{$ltable.DownSingular}}L) Load{{$rel.Foreign}}({{if $.NoContext}}e boil.E
}

{{if $usesPrimitives -}}
args[obj.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(obj.{{$col}})] = obj.{{$col}}
{{else -}}
if !queries.IsNil(obj.{{$col}}) {
args[obj.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(obj.{{$col}})] = obj.{{$col}}
}
{{end}}
}
@@ -71,7 +71,7 @@ func ({{$ltable.DownSingular}}L) Load{{$rel.Foreign}}({{if $.NoContext}}e boil.E

argsSlice := make([]interface{}, len(args))
i := 0
for arg := range args {
for _, arg := range args {
argsSlice[i] = arg
i++
}
8 changes: 4 additions & 4 deletions templates/main/08_relationship_one_to_one_eager.go.tpl
Original file line number Diff line number Diff line change
@@ -37,19 +37,19 @@ func ({{$ltable.DownSingular}}L) Load{{$relAlias.Local}}({{if $.NoContext}}e boi
}
}

args := make(map[interface{}]struct{})
args := make(map[interface{}]interface{})
if singular {
if object.R == nil {
object.R = &{{$ltable.DownSingular}}R{}
}
args[object.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(object.{{$col}})] = object.{{$col}}
} else {
for _, obj := range slice {
if obj.R == nil {
obj.R = &{{$ltable.DownSingular}}R{}
}

args[obj.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(obj.{{$col}})] = obj.{{$col}}
}
}

@@ -59,7 +59,7 @@ func ({{$ltable.DownSingular}}L) Load{{$relAlias.Local}}({{if $.NoContext}}e boi

argsSlice := make([]interface{}, len(args))
i := 0
for arg := range args {
for _, arg := range args {
argsSlice[i] = arg
i++
}
8 changes: 4 additions & 4 deletions templates/main/09_relationship_to_many_eager.go.tpl
Original file line number Diff line number Diff line change
@@ -38,18 +38,18 @@ func ({{$ltable.DownSingular}}L) Load{{$relAlias.Local}}({{if $.NoContext}}e boi
}
}

args := make(map[interface{}]struct{})
args := make(map[interface{}]interface{})
if singular {
if object.R == nil {
object.R = &{{$ltable.DownSingular}}R{}
}
args[object.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(object.{{$col}})] = object.{{$col}}
} else {
for _, obj := range slice {
if obj.R == nil {
obj.R = &{{$ltable.DownSingular}}R{}
}
args[obj.{{$col}}] = struct{}{}
args[boil.GenLoadMapKey(obj.{{$col}})] = obj.{{$col}}
}
}

@@ -59,7 +59,7 @@ func ({{$ltable.DownSingular}}L) Load{{$relAlias.Local}}({{if $.NoContext}}e boi

argsSlice := make([]interface{}, len(args))
i := 0
for arg := range args {
for _, arg := range args {
argsSlice[i] = arg
i++
}