mirror of https://github.com/go-gorm/gorm.git
Strict select argument check for Count
This commit is contained in:
parent
2f27f0f27f
commit
35a2a004d8
2
scope.go
2
scope.go
|
@ -917,7 +917,7 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scope *Scope) count(value interface{}) *Scope {
|
func (scope *Scope) count(value interface{}) *Scope {
|
||||||
if query, ok := scope.Search.selects["query"]; !ok || !strings.Contains(fmt.Sprint(query), "count(") {
|
if query, ok := scope.Search.selects["query"]; !ok || !regexp.MustCompile("(?i)^count(.+)$").MatchString(fmt.Sprint(query)) {
|
||||||
scope.Search.Select("count(*)")
|
scope.Search.Select("count(*)")
|
||||||
}
|
}
|
||||||
scope.Search.countingQuery = true
|
scope.Search.countingQuery = true
|
||||||
|
|
Loading…
Reference in New Issue