// getAttributeValuesForWebsites creates a map where the key is the attribute ID and // each part of the StringEntities slice are the full attribute values for a website ID. func getAttributeValuesForWebsites(ctx *context) map[string][]codegen.StringEntities { var tws store.TableWebsiteSlice tws.Load(ctx.dbrConn.NewSession(nil), func(sb *dbr.SelectBuilder) *dbr.SelectBuilder { return sb.Where("website_id > 0") }) // key contains the attributeID as a string var aws = make(map[string][]codegen.StringEntities) tew, err := ctx.aat.TableEavWebsite() codegen.LogFatal(err) if tew != nil { // only for those who have a wbesite specific table for _, w := range tws { aCollection, err := codegen.LoadStringEntities(ctx.db, getAttrSelect(ctx, w.WebsiteID)) codegen.LogFatal(err) for _, row := range aCollection { if aid, ok := row["attribute_id"]; ok { if nil == aws[aid] { aws[aid] = make([]codegen.StringEntities, 0, 200) // up to 200 websites at once } aws[aid] = append(aws[aid], row) } else { codegen.LogFatal(errgo.Newf("Column attribute_id not found in collection %#v\n", aCollection)) } } } } return aws }
func attrGenerateData(ctx *context) map[string]interface{} { websiteID := int64(0) // always 0 because we're building the base struct columns := getAttrColumns(ctx, websiteID) attributeCollection, err := codegen.LoadStringEntities(ctx.db, getAttrSelect(ctx, websiteID)) codegen.LogFatal(err) pkg := getPackage(ctx.et) importPaths := codegen.PrepareForTemplate(columns, attributeCollection, codegen.ConfigAttributeModel, pkg) return map[string]interface{}{ "AttrCol": attributeCollection, "AttrPkg": getAttrPkg(ctx.et), "AttrPkgImp": codegen.ConfigMaterializationAttributes[ctx.et.EntityTypeCode].AttrPkgImp, "AttrStruct": codegen.ConfigMaterializationAttributes[ctx.et.EntityTypeCode].AttrStruct, "FuncCollection": codegen.ConfigMaterializationAttributes[ctx.et.EntityTypeCode].FuncCollection, "FuncGetter": codegen.ConfigMaterializationAttributes[ctx.et.EntityTypeCode].FuncGetter, "ImportPaths": importPaths, "MyStruct": codegen.ConfigMaterializationAttributes[ctx.et.EntityTypeCode].MyStruct, "Name": getStructName(ctx, "attribute"), "PackageName": pkg, } }