Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package models
- import (
- "context"
- "time"
- "fmt"
- "github.com/tikasan/goa"
- "github.com/tikasan/goa-simple-sample/app"
- )
- // 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 c []*Category
- var objs []*app.BottleRelation
- //m.Db.Debug().Find(&native).Related(&c, "Categories")
- rows, _ := m.Db.Debug().Table(m.TableName()).Select("*").Joins("LEFT JOIN bottle_categories ON bottle_categories.bottle_id = bottles.id").
- Joins("LEFT JOIN categories ON bottle_categories.category_id = categories.id").
- Rows()
- for rows.Next() {
- fmt.Println(rows)
- }
- for _, v := range native {
- for k2, v2 := range v.Categories {
- fmt.Println(k2, v2)
- }
- }
- err := m.Db.Scopes(BottleFilterByAccount(accountID, m.Db)).
- Table(m.TableName()).
- Joins("LEFT JOIN bottle_categories ON bottle_categories.bottle_id = bottles.id").
- Joins("LEFT JOIN categories ON bottle_categories.category_id = categories.id").
- Find(&native).
- Error
- //_ = m.Db.Scopes(BottleFilterByAccount(accountID, m.Db)).
- // Table(m.TableName()).
- // Preload("BottleCategories").
- // Preload("Account").
- // Related(&related, "Categories").
- // 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement