diff --git a/model/criteria/criteria_test.go b/model/criteria/criteria_test.go index 5f43dc0e1..6ac2eb7c5 100644 --- a/model/criteria/criteria_test.go +++ b/model/criteria/criteria_test.go @@ -81,4 +81,10 @@ var _ = Describe("Criteria", func() { gomega.Expect(string(j)).To(gomega.Equal(jsonObj)) }) + It("allows sort by random", func() { + newObj := goObj + newObj.Sort = "random" + gomega.Expect(newObj.OrderBy()).To(gomega.Equal("random() asc")) + }) + }) diff --git a/model/criteria/fields.go b/model/criteria/fields.go index b14aa5d08..205861f90 100644 --- a/model/criteria/fields.go +++ b/model/criteria/fields.go @@ -43,6 +43,7 @@ var fieldMap = map[string]*mappedField{ "lastplayed": {field: "annotation.play_date"}, "playcount": {field: "COALESCE(annotation.play_count, 0)", order: "annotation.play_count"}, "rating": {field: "COALESCE(annotation.rating, 0)", order: "annotation.rating"}, + "random": {field: "-", order: "random()"}, } type mappedField struct {