From a81b9f3950e7ee443235c07232ba99db858864f4 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 28 Oct 2013 09:18:34 +0800 Subject: [PATCH] Update README --- README.md | 5 +++++ orm_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 9b3b25db..73a123cf 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ db.Order("age desc, name").Find(&users) //// users -> select * from users order by age desc, name; db.Order("age desc").Order("name").Find(&users) //// users -> select * from users order by age desc, name; +// ReOrder +db.Order("age desc").Find(&users1).Order("age", true).Find(&users2) +//// users1 -> select * from users order by age desc; +//// users2 -> select * from users order by age; + // Limit db.Limit(3).Find(&users) diff --git a/orm_test.go b/orm_test.go index fd987db9..68365798 100644 --- a/orm_test.go +++ b/orm_test.go @@ -315,6 +315,18 @@ func TestOrderAndPluck(t *testing.T) { t.Errorf("The first age should be 26 because of ordered by") } + var ages1, ages2 []int64 + db.Model(&[]User{}).Order("age desc").Pluck("age", &ages1).Order("age").Pluck("age", &ages2) + if !reflect.DeepEqual(ages1, ages2) { + t.Errorf("The first order is the primary order") + } + + var ages3, ages4 []int64 + db.Model(&[]User{}).Order("age desc").Pluck("age", &ages3).Order("age", true).Pluck("age", &ages4) + if reflect.DeepEqual(ages3, ages4) { + t.Errorf("Reorder should works well") + } + ages = []int64{} var names []string db.Model(&User{}).Order("name").Order("age desc").Pluck("age", &ages).Pluck("name", &names)