Update README

This commit is contained in:
Jinzhu 2013-10-28 09:18:34 +08:00
parent 7e68ad9773
commit a81b9f3950
2 changed files with 17 additions and 0 deletions

View File

@ -63,6 +63,11 @@ db.Order("age desc, name").Find(&users)
//// users -> select * from users order by age desc, name; //// users -> select * from users order by age desc, name;
db.Order("age desc").Order("name").Find(&users) db.Order("age desc").Order("name").Find(&users)
//// users -> select * from users order by age desc, name; //// 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 // Limit
db.Limit(3).Find(&users) db.Limit(3).Find(&users)

View File

@ -315,6 +315,18 @@ func TestOrderAndPluck(t *testing.T) {
t.Errorf("The first age should be 26 because of ordered by") 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{} ages = []int64{}
var names []string var names []string
db.Model(&User{}).Order("name").Order("age desc").Pluck("age", &ages).Pluck("name", &names) db.Model(&User{}).Order("name").Order("age desc").Pluck("age", &ages).Pluck("name", &names)