sort GORM options before apply

This commit is contained in:
Jinzhu 2021-04-09 11:43:24 +08:00
parent ad53074f1d
commit d278ca49ef
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"sort"
"sync"
"time"
@ -111,6 +112,12 @@ type Session struct {
func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
config := &Config{}
sort.Slice(opts, func(i, j int) bool {
_, isConfig := opts[i].(*Config)
_, isConfig2 := opts[j].(*Config)
return isConfig && !isConfig2
})
for _, opt := range opts {
if opt != nil {
if err := opt.Apply(config); err != nil {