Clean up the byte primary key stuff
This commit is contained in:
parent
c624943f53
commit
32561717b1
7 changed files with 28 additions and 29 deletions
|
@ -4,6 +4,9 @@
|
|||
{{- with .Rel -}}
|
||||
{{- $arg := printf "maybe%s" .LocalTable.NameGo -}}
|
||||
{{- $slice := printf "%sSlice" .LocalTable.NameGo -}}
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $foreignTableFKeyCol := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $usesBytes := eq "[]byte" $foreignTableFKeyCol.Type}}
|
||||
// Load{{.Function.Name}} allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects.
|
||||
func ({{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error {
|
||||
|
@ -67,11 +70,7 @@ func ({{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bo
|
|||
|
||||
for _, foreign := range resultSlice {
|
||||
for _, local := range slice {
|
||||
{{/* Use the foreign table (the one without the fkey) to avoid null types in the id type */}}
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $column := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $type := $column.Type -}}
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 == bytes.Compare(local.{{.Function.LocalAssignment}}, foreign.{{.Function.ForeignAssignment}}) {
|
||||
{{else -}}
|
||||
if local.{{.Function.LocalAssignment}} == foreign.{{.Function.ForeignAssignment}} {
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
{{- $arg := printf "maybe%s" $txt.LocalTable.NameGo -}}
|
||||
{{- $slice := printf "%sSlice" $txt.LocalTable.NameGo -}}
|
||||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}}
|
||||
{{- $fkeyCol := $dot.Table.GetColumn .Column -}}
|
||||
{{- $usesBytes := eq "[]byte" $fkeyCol.Type -}}
|
||||
// Load{{$txt.Function.Name}} allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects.
|
||||
func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error {
|
||||
|
@ -106,13 +108,11 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
|
|||
return nil
|
||||
}
|
||||
|
||||
{{$column := $dot.Table.GetColumn .Column -}}
|
||||
{{- $type := $column.Type -}}
|
||||
{{if .ToJoinTable -}}
|
||||
for i, foreign := range resultSlice {
|
||||
localJoinCol := localJoinCols[i]
|
||||
for _, local := range slice {
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 == bytes.Compare(local.{{$txt.Function.LocalAssignment}}, localJoinCol) {
|
||||
{{else -}}
|
||||
if local.{{$txt.Function.LocalAssignment}} == localJoinCol {
|
||||
|
@ -128,7 +128,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
|
|||
{{else -}}
|
||||
for _, foreign := range resultSlice {
|
||||
for _, local := range slice {
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 == bytes.Compare(local.{{$txt.Function.LocalAssignment}}, foreign.{{$txt.Function.ForeignAssignment}}) {
|
||||
{{else -}}
|
||||
if local.{{$txt.Function.LocalAssignment}} == foreign.{{$txt.Function.ForeignAssignment}} {
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
{{- $dot := .Dot -}}{{/* .Dot holds the root templateData struct, passed in through preserveDot */}}
|
||||
{{- with .Rel -}}
|
||||
{{- $varNameSingular := .ForeignKey.ForeignTable | singular | camelCase -}}
|
||||
{{- $localNameSingular := .ForeignKey.Table | singular | camelCase}}
|
||||
{{- $localNameSingular := .ForeignKey.Table | singular | camelCase -}}
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $foreignTableFKeyCol := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $usesBytes := eq "[]byte" $foreignTableFKeyCol.Type -}}
|
||||
// Set{{.Function.Name}} of the {{.ForeignKey.Table | singular}} to the related item.
|
||||
// Sets {{.Function.Receiver}}.R.{{.Function.Name}} to related.
|
||||
// Adds {{.Function.Receiver}} to related.R.{{.Function.ForeignName}}.
|
||||
|
@ -75,10 +78,7 @@ func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) Remove{{.Function.Name}}(e
|
|||
related.R.{{.Function.ForeignName}} = nil
|
||||
{{else -}}
|
||||
for i, ri := range related.R.{{.Function.ForeignName}} {
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $column := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $type := $column.Type}}
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 != bytes.Compare({{.Function.Receiver}}.{{.Function.LocalAssignment}}, ri.{{.Function.LocalAssignment}}) {
|
||||
{{else -}}
|
||||
if {{.Function.Receiver}}.{{.Function.LocalAssignment}} != ri.{{.Function.LocalAssignment}} {
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
{{- template "relationship_to_one_test_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $fkeyCol := $dot.Table.GetColumn .Column -}}
|
||||
{{- $usesBytes := eq "[]byte" $fkeyCol.Type}}
|
||||
func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
||||
var err error
|
||||
tx := MustTx(boil.Begin())
|
||||
|
@ -60,9 +62,7 @@ func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
|||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range {{$varname}} {
|
||||
{{- $column := $dot.Table.GetColumn .Column -}}
|
||||
{{- $type := $column.Type}}
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 == bytes.Compare(v.{{$rel.Function.ForeignAssignment}}, b.{{$rel.Function.ForeignAssignment}}) {
|
||||
bFound = true
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
{{- $varNameSingular := .Table | singular | camelCase -}}
|
||||
{{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $column := $dot.Table.GetColumn .Column -}}
|
||||
{{- $type := $column.Type}}
|
||||
{{- $fkeyCol := $dot.Table.GetColumn .Column -}}
|
||||
{{- $usesBytes := eq "[]byte" $fkeyCol.Type}}
|
||||
func test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}}(t *testing.T) {
|
||||
var err error
|
||||
|
||||
|
@ -64,7 +64,7 @@ func test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}}(t *testing.
|
|||
}
|
||||
{{- else}}
|
||||
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 != bytes.Compare(a.{{$rel.Function.LocalAssignment}}, first.{{$rel.Function.ForeignAssignment}}) {
|
||||
t.Error("foreign key was wrong value", a.{{$rel.Function.LocalAssignment}}, first.{{$rel.Function.ForeignAssignment}})
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ func test{{$rel.LocalTable.NameGo}}ToManySetOp{{$rel.Function.Name}}(t *testing.
|
|||
if c.{{$rel.ForeignTable.ColumnNameGo}}.Valid {
|
||||
t.Error("want c's foreign key value to be nil")
|
||||
}
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 != bytes.Compare(a.{{$rel.Function.LocalAssignment}}, d.{{$rel.Function.ForeignAssignment}}) {
|
||||
t.Error("foreign key was wrong value", a.{{$rel.Function.LocalAssignment}}, d.{{$rel.Function.ForeignAssignment}})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{{- define "relationship_to_one_test_helper"}}
|
||||
{{- $dot := .Dot -}}
|
||||
{{- with .Rel -}}
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $foreignTableFKeyCol := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $usesBytes := eq "[]byte" $foreignTableFKeyCol.Type -}}
|
||||
func test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(t *testing.T) {
|
||||
tx := MustTx(boil.Begin())
|
||||
defer tx.Rollback()
|
||||
|
@ -39,10 +42,7 @@ func test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
{{$foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $column := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $type := $column.Type -}}
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 == bytes.Compare(check.{{.Function.ForeignAssignment}}, foreign.{{.Function.ForeignAssignment}}) {
|
||||
{{else -}}
|
||||
if check.{{.Function.ForeignAssignment}} != foreign.{{.Function.ForeignAssignment}} {
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
{{- $varNameSingular := .ForeignKey.Table | singular | camelCase -}}
|
||||
{{- $foreignVarNameSingular := .ForeignKey.ForeignTable | singular | camelCase}}
|
||||
{{- $foreignTable := getTable $dot.Tables .ForeignKey.ForeignTable -}}
|
||||
{{- $column := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $type := $column.Type -}}
|
||||
{{- $foreignTableFKeyCol := $foreignTable.GetColumn .ForeignKey.ForeignColumn -}}
|
||||
{{- $usesBytes := eq "[]byte" $foreignTableFKeyCol.Type -}}
|
||||
func test{{.LocalTable.NameGo}}ToOneSetOp{{.ForeignTable.NameGo}}_{{.Function.Name}}(t *testing.T) {
|
||||
var err error
|
||||
|
||||
|
@ -39,7 +39,7 @@ func test{{.LocalTable.NameGo}}ToOneSetOp{{.ForeignTable.NameGo}}_{{.Function.Na
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 != bytes.Compare(a.{{.Function.LocalAssignment}}, x.{{.Function.ForeignAssignment}}) {
|
||||
{{else -}}
|
||||
if a.{{.Function.LocalAssignment}} != x.{{.Function.ForeignAssignment}} {
|
||||
|
@ -57,7 +57,7 @@ func test{{.LocalTable.NameGo}}ToOneSetOp{{.ForeignTable.NameGo}}_{{.Function.Na
|
|||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
{{if eq $type "[]byte" -}}
|
||||
{{if $usesBytes -}}
|
||||
if 0 != bytes.Compare(a.{{.Function.LocalAssignment}}, x.{{.Function.ForeignAssignment}}) {
|
||||
{{else -}}
|
||||
if a.{{.Function.LocalAssignment}} != x.{{.Function.ForeignAssignment}} {
|
||||
|
|
Loading…
Reference in a new issue