mirror of https://github.com/go-gorm/gorm.git
Test group with table name
This commit is contained in:
parent
a550a05882
commit
d5d31b38a7
|
@ -6,10 +6,10 @@ require (
|
||||||
github.com/google/uuid v1.1.1
|
github.com/google/uuid v1.1.1
|
||||||
github.com/jinzhu/now v1.1.1
|
github.com/jinzhu/now v1.1.1
|
||||||
github.com/lib/pq v1.6.0
|
github.com/lib/pq v1.6.0
|
||||||
gorm.io/driver/mysql v0.2.6
|
gorm.io/driver/mysql v0.2.7
|
||||||
gorm.io/driver/postgres v0.2.3
|
gorm.io/driver/postgres v0.2.4
|
||||||
gorm.io/driver/sqlite v1.0.7
|
gorm.io/driver/sqlite v1.0.8
|
||||||
gorm.io/driver/sqlserver v0.2.3
|
gorm.io/driver/sqlserver v0.2.4
|
||||||
gorm.io/gorm v0.2.9
|
gorm.io/gorm v0.2.9
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,14 @@ func TestGroupBy(t *testing.T) {
|
||||||
t.Errorf("name should be groupby, but got %v, total should be 60, but got %v", name, total)
|
t.Errorf("name should be groupby, but got %v, total should be 60, but got %v", name, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := DB.Model(&User{}).Select("name, sum(age)").Where("name = ?", "groupby").Group("users.name").Row().Scan(&name, &total); err != nil {
|
||||||
|
t.Errorf("no error should happen, but got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if name != "groupby" || total != 60 {
|
||||||
|
t.Errorf("name should be groupby, but got %v, total should be 60, but got %v", name, total)
|
||||||
|
}
|
||||||
|
|
||||||
if err := DB.Model(&User{}).Select("name, sum(age) as total").Where("name LIKE ?", "groupby%").Group("name").Having("name = ?", "groupby1").Row().Scan(&name, &total); err != nil {
|
if err := DB.Model(&User{}).Select("name, sum(age) as total").Where("name LIKE ?", "groupby%").Group("name").Having("name = ?", "groupby1").Row().Scan(&name, &total); err != nil {
|
||||||
t.Errorf("no error should happen, but got %v", err)
|
t.Errorf("no error should happen, but got %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue