From 59c238539ddc3e0ee964e24f0f30910875c88334 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Thu, 26 Jan 2017 22:06:47 -0800 Subject: [PATCH] Attach all eagerly loaded models in to-one - The problem here is that due to the nature of the relationship and the way the loop was set up it was possible to miss some relationships: A _ C \_ D B _ E \_ F Since we looped over A and B and did a break when we found something to attach it to (in this example A would find C) it would break. What we should be looping through is CDEF and finding a home for each one. Did the same change in to_one though it doesn't matter since it's one-to-one. to-many is untouched because it's already looping over CDEF and finding a home for it because the relationship is reversed. - Fix #98 --- templates/07_relationship_to_one_eager.tpl | 10 +++++++--- templates/08_relationship_one_to_one_eager.tpl | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/templates/07_relationship_to_one_eager.tpl b/templates/07_relationship_to_one_eager.tpl index 43392f0..4af84ca 100644 --- a/templates/07_relationship_to_one_eager.tpl +++ b/templates/07_relationship_to_one_eager.tpl @@ -65,13 +65,17 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula } {{- end}} - if singular && len(resultSlice) != 0 { + if len(resultSlice) == 0 { + return nil + } + + if singular { object.R.{{$txt.Function.Name}} = resultSlice[0] return nil } - for _, foreign := range resultSlice { - for _, local := range slice { + for _, local := range slice { + for _, foreign := range resultSlice { {{if $txt.Function.UsesBytes -}} if 0 == bytes.Compare(local.{{$txt.Function.LocalAssignment}}, foreign.{{$txt.Function.ForeignAssignment}}) { {{else -}} diff --git a/templates/08_relationship_one_to_one_eager.tpl b/templates/08_relationship_one_to_one_eager.tpl index 6603d55..7363b69 100644 --- a/templates/08_relationship_one_to_one_eager.tpl +++ b/templates/08_relationship_one_to_one_eager.tpl @@ -65,13 +65,17 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula } {{- end}} - if singular && len(resultSlice) != 0 { + if len(resultSlice) == 0 { + return nil + } + + if singular { object.R.{{$txt.Function.Name}} = resultSlice[0] return nil } - for _, foreign := range resultSlice { - for _, local := range slice { + for _, local := range slice { + for _, foreign := range resultSlice { {{if $txt.Function.UsesBytes -}} if 0 == bytes.Compare(local.{{$txt.Function.LocalAssignment}}, foreign.{{$txt.Function.ForeignAssignment}}) { {{else -}}