Suppose my table name is A. I want to sort the table records on basis of column come from request. How should i write this in gorm query
I was trying this
Order(A['columnName'] desc)
but it was not working.
Can you please help on this, how to achieve this type of behaviour using gorm?
The document you expected this should be explained
Expected answer
Order(A['columnName'] desc)
How to make dynamic order by clause on column working
Comment From: emregullu
Hi @sagg1295-swiggy,
Assuming columnName is a string variable with the value of the name of the column that you want to order by, you can achieve this type of behaviour as follows,
db.Model(&User{}).Order(clause.OrderByColumn{
Column: clause.Column{Name: columnName},
Desc: true,
}).Find(&result)