more robust ordering on categories

This commit is contained in:
Dan Ballard 2015-05-19 08:32:35 -07:00
parent e75c81fa36
commit ff9c3e7f77
1 changed files with 2 additions and 2 deletions

View File

@ -22,7 +22,7 @@ func LoadCategories(db *sql.DB) {
CategoriesTree = []*Category{}
CategoriesFlat = make(map[int]*Category)
rows, err := db.Query("select categories.id, categories.name, categories.parent_id from categories order by id,Categories.parent_id desc")
rows, err := db.Query("select categories.id, categories.name, categories.parent_id from categories order by coalesce(parent_id, id), parent_id is not null")
if err != nil {
fmt.Println("DB Error loading Categories:", err)
return
@ -36,7 +36,7 @@ func LoadCategories(db *sql.DB) {
if err != nil {
fmt.Println("Categories DB Error: ", err)
}
CategoriesFlat[category.Id] = category
if category.Parent.Valid {