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" | 	"context" | ||||||
| 	"database/sql" | 	"database/sql" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"sort" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| @ -111,6 +112,12 @@ type Session struct { | |||||||
| func Open(dialector Dialector, opts ...Option) (db *DB, err error) { | func Open(dialector Dialector, opts ...Option) (db *DB, err error) { | ||||||
| 	config := &Config{} | 	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 { | 	for _, opt := range opts { | ||||||
| 		if opt != nil { | 		if opt != nil { | ||||||
| 			if err := opt.Apply(config); err != nil { | 			if err := opt.Apply(config); err != nil { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu