Hopefully this is my last question to do with pointers ever:
I am calling a repository method to get a slice of gym classes. I am displaying them in a view like this:
{{ range .}}
{{.VideoPath}} << Correct
<br>
{{.Instructor.Email}} << Blank
<br>
{{.ClassType.ClassTypeCode}} << Blank
{{end}}
The instructor and classtype fields are coming up as empty structs, but in the ClassRepository I did some Printlns and the correct data gets printed. Somewhere there is a pointer issue or something. What have I done wrong?
Here is the repository:
package repositories
type ClassRepository struct {
Gorp gorp.SqlExecutor
}
func (c ClassRepository) ClassesForLastNDays(days int) []entities.Class {
var classes []entities.Class
// Gets the classes - omitted for brevity
c.populateClassRelationships(classes)
return classes
}
func (c ClassRepository) populateClassRelationships(classes []entities.Class) {
for i := range classes {
class := classes[i]
// ClassType
obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode)
if err != nil {
panic(err)
}
class.ClassType = *obj.(*entities.ClassType)
fmt.Println(class.ClassType) << Returns correct data
// Instructor and Equipment
Same for instructor and Equipment
}
}
UPDATE:
After a whole lot of printlns I can confirm that the issue is here after populateClassRelationships the populated values are all lost.
func (c ClassRepository) ClassesForLastNDays(days int) []entities.Class {
var classes []entities.Class
// Gets the classes - omitted for brevity
c.populateClassRelationships(classes) <<<< In the method,Println has values
return classes <<<< Values have been lost
}