forked from mirror/gorm
Allow to use sql function in Group, Pluck
This commit is contained in:
parent
3e4dbde920
commit
7aaac3a580
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue