Last active
April 18, 2019 05:59
-
-
Save AbsolutelySaurabh/939c66b1aa8111d52a366f7071f9dbc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//db.go | |
SELECT_DISTINCT_MASTER_TYPES = "select distinct master_type from master_types" | |
//admin.go | |
master_type := Admin.AddResource(&models.MasterType{}, &admin.Config{ | |
Permission: configuration.GetPermission(C.MODEL_MASTER_TYPE), | |
PageCount: C.PAGE_COUNT}) | |
master_type.Meta(&admin.Meta{ | |
Name: "Master_Type", | |
Type: "select_one", | |
Collection: getMasterTypeCollection, | |
}) | |
func getMasterTypeCollection(res interface{}, ctx *qor.Context) (results [][]string) { | |
db := configuration.GetDB(C.READ) | |
rows, err := db.Raw(C.SELECT_DISTINCT_MASTER_TYPES).Rows() | |
if err == nil { | |
defer rows.Close() | |
for rows.Next() { | |
var master models.MasterType | |
db.ScanRows(rows, &master) | |
results = append(results, []string{master.Master_Type, master.Master_Type}) | |
} | |
} else { | |
logs.GetLogger().Error("Error while getting distinct master_type from master_types table. %s", err) | |
errors.New("Error while getting distinct master_type from master_types table.") | |
} | |
return results | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment