diff --git a/boil/load_map_key.go b/boil/load_map_key.go new file mode 100644 index 000000000..659d46e1f --- /dev/null +++ b/boil/load_map_key.go @@ -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 + } + +} diff --git a/templates/main/07_relationship_to_one_eager.go.tpl b/templates/main/07_relationship_to_one_eager.go.tpl index ce68d02bb..b6391885e 100644 --- a/templates/main/07_relationship_to_one_eager.go.tpl +++ b/templates/main/07_relationship_to_one_eager.go.tpl @@ -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++ } diff --git a/templates/main/08_relationship_one_to_one_eager.go.tpl b/templates/main/08_relationship_one_to_one_eager.go.tpl index 99fec29ba..b8168c15a 100644 --- a/templates/main/08_relationship_one_to_one_eager.go.tpl +++ b/templates/main/08_relationship_one_to_one_eager.go.tpl @@ -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++ } diff --git a/templates/main/09_relationship_to_many_eager.go.tpl b/templates/main/09_relationship_to_many_eager.go.tpl index 81643be33..42fcba676 100644 --- a/templates/main/09_relationship_to_many_eager.go.tpl +++ b/templates/main/09_relationship_to_many_eager.go.tpl @@ -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++ }