gorm icon indicating copy to clipboard operation
gorm copied to clipboard

Sort has_many items

Open ski7777 opened this issue 2 years ago • 0 comments

Is there a way to sort the items in a has-many-association? I have one model A that has many of B (fields: a, b, sort) and in B there is a variable to sort the items (sort). Is there a way to associate A.ID and B.a and get a list of B.b sorted by B.sort?

The document you expected this should be explained

https://gorm.io/docs/has_many.html

Expected answer

I currently solved this with an AfterFind.Hook but I hope there is a better (performing) solution

ski7777 avatar Jun 03 '22 00:06 ski7777