Your Question
There is a way to order by FIELD and multiple columns at the same time?
Clauses(clause.OrderBy{
Expression: clause.Expr{SQL: "FIELD(gender,?)", Vars: []interface{}{[]string{"f", "c", "t", "m"}}, WithoutParentheses: true},
Columns: []clause.OrderByColumn{
{Column: clause.Column{Name: "status"}, Desc: true},
{Column: clause.Column{Name: "seconds_online"}, Desc: true},
},
}).
The sql result from GORM is SELECT * FROM `table` ORDER BY FIELD(gender,'f','c','t','m')
The document you expected this should be explained
https://gorm.io/docs/query.html#Order
Expected answer
SELECT * FROM `table` ORDER BY FIELD(gender, 'f', 'c', 't', 'm'), `status` DESC, `seconds_online` DESC LIMIT 20
Comment From: marianvlad
Found a simpler way
Order("FIELD(gender, 'f', 'c', 't', 'm')").
Order("status desc, seconds_online desc").