From d5d31b38a7442f44da356cc413ad4afb30fa1abb Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 26 Jun 2020 08:39:18 +0800 Subject: [PATCH] Test group with table name --- tests/go.mod | 8 ++++---- tests/group_by_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index 955bafe2..c467f34b 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,10 +6,10 @@ require ( github.com/google/uuid v1.1.1 github.com/jinzhu/now v1.1.1 github.com/lib/pq v1.6.0 - gorm.io/driver/mysql v0.2.6 - gorm.io/driver/postgres v0.2.3 - gorm.io/driver/sqlite v1.0.7 - gorm.io/driver/sqlserver v0.2.3 + gorm.io/driver/mysql v0.2.7 + gorm.io/driver/postgres v0.2.4 + gorm.io/driver/sqlite v1.0.8 + gorm.io/driver/sqlserver v0.2.4 gorm.io/gorm v0.2.9 ) diff --git a/tests/group_by_test.go b/tests/group_by_test.go index b08f48f1..6d0ed39c 100644 --- a/tests/group_by_test.go +++ b/tests/group_by_test.go @@ -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) } + 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 { t.Errorf("no error should happen, but got %v", err) }