diff --git a/chainable_api.go b/chainable_api.go index dbd783fd..e2ba44cc 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -162,8 +162,10 @@ func (db *DB) Joins(query string, args ...interface{}) (tx *DB) { // Group specify the group method on the find func (db *DB) Group(name string) (tx *DB) { tx = db.getInstance() + + fields := strings.FieldsFunc(name, utils.IsChar) tx.Statement.AddClause(clause.GroupBy{ - Columns: []clause.Column{{Name: name}}, + Columns: []clause.Column{{Name: name, Raw: len(fields) != 1}}, }) return } diff --git a/finisher_api.go b/finisher_api.go index 6d961811..af040106 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -8,6 +8,7 @@ import ( "strings" "gorm.io/gorm/clause" + "gorm.io/gorm/utils" ) // Create insert the value into database @@ -325,9 +326,10 @@ func (db *DB) Pluck(column string, dest interface{}) (tx *DB) { tx.AddError(ErrorModelValueRequired) } + fields := strings.FieldsFunc(column, utils.IsChar) tx.Statement.AddClauseIfNotExists(clause.Select{ Distinct: tx.Statement.Distinct, - Columns: []clause.Column{{Name: column}}, + Columns: []clause.Column{{Name: column, Raw: len(fields) != 1}}, }) tx.Statement.Dest = dest tx.callbacks.Query().Execute(tx)