Skip to content

Instantly share code, notes, and snippets.

@pei0804
Created May 19, 2017 12:49
Show Gist options
  • Save pei0804/c980965e8facdc20ba7c0ae1f30d3c18 to your computer and use it in GitHub Desktop.
Save pei0804/c980965e8facdc20ba7c0ae1f30d3c18 to your computer and use it in GitHub Desktop.
goa-sample-model
// ListBottle returns an array of view: default.
func (m *BottleDB) ListBottleFullScan(ctx context.Context, accountID int) []*app.BottleRelation {
defer goa.MeasureSince([]string{"goa", "db", "bottle", "listbottle"}, time.Now())
var native []*Bottle
var objs []*app.BottleRelation
err := m.Db.Scopes(BottleFilterByAccount(accountID, m.Db)).
Table(m.TableName()).
Preload("BottleCategories").
Preload("Account").
Find(&native).
Error
for k, v := range native {
for k2, v2 := range v.BottleCategories {
native2 := []*BottleCategory{}
m.Db.Preload("Category").
Where("bottle_id = ?", v2.BottleID).
Find(&native2)
native[k].Categories = append(native[k].Categories, native2[k2].Category)
}
}
if err != nil {
goa.LogError(ctx, "error listing Bottle", "error", err.Error())
return objs
}
for _, t := range native {
objs = append(objs, t.BottleToBottleRelation())
}
return objs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment