Makes order of values deterministic for IN(?, ?..) style query
Currently during preloads of associations the order of parameterized/comma- separated values for IN(?, ?..) style query is not deterministic. This commit fixes that which removes random failure when writing tests which asserts exact queries run (e.g. using DATA-DOG/go-sqlmock library or such).
This commit is contained in:
parent
7180bd0f27
commit
20cb84ca8d
11
scope.go
11
scope.go
@ -1324,7 +1324,7 @@ func (scope *Scope) autoIndex() *Scope {
|
||||
}
|
||||
|
||||
func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
|
||||
resultMap := make(map[string][]interface{})
|
||||
resultMap := make(map[string]bool)
|
||||
for _, value := range values {
|
||||
indirectValue := indirect(reflect.ValueOf(value))
|
||||
|
||||
@ -1345,7 +1345,8 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
|
||||
if hasValue {
|
||||
h := fmt.Sprint(result...)
|
||||
if _, exist := resultMap[h]; !exist {
|
||||
resultMap[h] = result
|
||||
resultMap[h] = true
|
||||
results = append(results, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1363,14 +1364,12 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
|
||||
if hasValue {
|
||||
h := fmt.Sprint(result...)
|
||||
if _, exist := resultMap[h]; !exist {
|
||||
resultMap[h] = result
|
||||
resultMap[h] = true
|
||||
results = append(results, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range resultMap {
|
||||
results = append(results, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user