
This commit adds more ways of specifying selects: -) You can now pass in a []string. This is mostly for convenience, since you may want to dynamically create a list of fields to be selected. -) You can now use variables. This is important because a select could take user input. For example, finding a MAX between a record and a given number could be easily done using select, and then you don't have to process anything in backend logic. This is also necessary to use postgres text search capabilities (which actaully play nicely with the rest of gorm). -) You can now chain select calls. This could be useful in conjunction with gorm's scopes functionality.
31 lines
672 B
Go
31 lines
672 B
Go
package gorm
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestCloneSearch(t *testing.T) {
|
|
s := new(search)
|
|
s.where("name = ?", "jinzhu").order("name").attrs("name", "jinzhu").selects("name, age")
|
|
|
|
s1 := s.clone()
|
|
s1.where("age = ?", 20).order("age").attrs("email", "a@e.org").selects("email")
|
|
|
|
if reflect.DeepEqual(s.WhereConditions, s1.WhereConditions) {
|
|
t.Errorf("Where should be copied")
|
|
}
|
|
|
|
if reflect.DeepEqual(s.Orders, s1.Orders) {
|
|
t.Errorf("Order should be copied")
|
|
}
|
|
|
|
if reflect.DeepEqual(s.InitAttrs, s1.InitAttrs) {
|
|
t.Errorf("InitAttrs should be copied")
|
|
}
|
|
|
|
if reflect.DeepEqual(s.Selects, s1.Selects) {
|
|
t.Errorf("selectStr should be copied")
|
|
}
|
|
}
|