Skip to content

Programmatically add order by #979

Answered by aarondl
gmhafiz asked this question in Q&A
Discussion options

You must be logged in to vote

There's nothing better than this. Though it doesn't seem like this is too onerous to make a little function in your code that does OrderByFromMap since all the types are generic. You can re-assign to mods and the function can change it if it's necessary or return the input if not.

mods := []qm.QueryMod{
  qm.Where("description LIKE ?", "%"+description+"%"),
  qm.Limit(limit),
  qm.Offset(offset),
}

mods = OrderByFromMap(map)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gmhafiz
Comment options

Answer selected by gmhafiz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants