forked from mirror/gorm
sort GORM options before apply
This commit is contained in:
parent
ad53074f1d
commit
d278ca49ef
7
gorm.go
7
gorm.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue