diff --git a/finisher_api.go b/finisher_api.go index d273093f..e98efc92 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -483,8 +483,6 @@ func (db *DB) Pluck(column string, dest interface{}) (tx *DB) { column = f.DBName } } - } else if tx.Statement.Table == "" { - tx.AddError(ErrModelValueRequired) } if len(tx.Statement.Selects) != 1 { diff --git a/tests/distinct_test.go b/tests/distinct_test.go index 29a320ff..f97738a7 100644 --- a/tests/distinct_test.go +++ b/tests/distinct_test.go @@ -31,6 +31,12 @@ func TestDistinct(t *testing.T) { AssertEqual(t, names1, []string{"distinct", "distinct-2", "distinct-3"}) + var names2 []string + DB.Scopes(func(db *gorm.DB) *gorm.DB { + return db.Table("users") + }).Where("name like ?", "distinct%").Order("name").Pluck("name", &names2) + AssertEqual(t, names2, []string{"distinct", "distinct", "distinct", "distinct-2", "distinct-3"}) + var results []User if err := DB.Distinct("name", "age").Where("name like ?", "distinct%").Order("name, age desc").Find(&results).Error; err != nil { t.Errorf("failed to query users, got error: %v", err)