forked from mirror/gorm
Fix batch find
This commit is contained in:
parent
09b6fc3ab0
commit
97fc5878e9
20
orm_test.go
20
orm_test.go
|
@ -1,9 +1,14 @@
|
||||||
package gorm
|
package gorm
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
Age int64
|
||||||
|
Birthday time.Time
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,3 +115,16 @@ func TestWhere(t *testing.T) {
|
||||||
t.Errorf("Shouldn't find anything when looking for none existing records, %+v", users)
|
t.Errorf("Shouldn't find anything when looking for none existing records, %+v", users)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestComplexWhere(t *testing.T) {
|
||||||
|
db.Save(&User{Name: "1", Age: 18})
|
||||||
|
db.Save(&User{Name: "2", Age: 20})
|
||||||
|
db.Save(&User{Name: "3", Age: 22})
|
||||||
|
db.Save(&User{Name: "3", Age: 24})
|
||||||
|
|
||||||
|
var users []User
|
||||||
|
db.Where("age > ?", 20).Find(&users)
|
||||||
|
if len(users) != 2 {
|
||||||
|
t.Errorf("Should only have 2 users age great than 20, but have %v", len(users))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
5
sql.go
5
sql.go
|
@ -65,7 +65,12 @@ func (s *Orm) query(out interface{}) {
|
||||||
values = append(values, dest.FieldByName(snakeToUpperCamel(value)).Addr().Interface())
|
values = append(values, dest.FieldByName(snakeToUpperCamel(value)).Addr().Interface())
|
||||||
}
|
}
|
||||||
s.Error = rows.Scan(values...)
|
s.Error = rows.Scan(values...)
|
||||||
|
|
||||||
|
if is_slice {
|
||||||
|
dest_out.Set(reflect.Append(dest_out, dest))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (counts == 0) && !is_slice {
|
if (counts == 0) && !is_slice {
|
||||||
s.Error = errors.New("Record not found!")
|
s.Error = errors.New("Record not found!")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue