fix
This commit is contained in:
		
							parent
							
								
									b0872f9a7e
								
							
						
					
					
						commit
						68fa604e91
					
				| @ -5,6 +5,7 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"go/ast" | 	"go/ast" | ||||||
|  | 	"path" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| @ -314,10 +315,12 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam | |||||||
| 		if methodValue := callBackToMethodValue(modelValue, cbName); methodValue.IsValid() { | 		if methodValue := callBackToMethodValue(modelValue, cbName); methodValue.IsValid() { | ||||||
| 			switch methodValue.Type().String() { | 			switch methodValue.Type().String() { | ||||||
| 			case "func(*gorm.DB) error": | 			case "func(*gorm.DB) error": | ||||||
| 				if inVarPkg := methodValue.Type().In(0).Elem().PkgPath(); inVarPkg != "gorm.io/gorm" { | 				expectedPkgPath := path.Dir(reflect.TypeOf(schema).Elem().PkgPath()) | ||||||
| 					logger.Default.Warn(context.Background(), "In model %v, the hook function `%v(*gorm.DB) error` has an incorrect parameter type. The expected parameter type is `gorm.io/gorm`, but the provided type is `%v`.", schema, cbName, inVarPkg) | 				if inVarPkg := methodValue.Type().In(0).Elem().PkgPath(); inVarPkg == expectedPkgPath { | ||||||
| 				} else { |  | ||||||
| 					reflect.Indirect(reflect.ValueOf(schema)).FieldByName(string(cbName)).SetBool(true) | 					reflect.Indirect(reflect.ValueOf(schema)).FieldByName(string(cbName)).SetBool(true) | ||||||
|  | 				} else { | ||||||
|  | 					logger.Default.Warn(context.Background(), "In model %v, the hook function `%v(*gorm.DB) error` has an incorrect parameter type. The expected parameter type is `%v`, but the provided type is `%v`.", schema, cbName, expectedPkgPath, inVarPkg) | ||||||
|  | 					// PASS
 | ||||||
| 				} | 				} | ||||||
| 			default: | 			default: | ||||||
| 				logger.Default.Warn(context.Background(), "Model %v don't match %vInterface, should be `%v(*gorm.DB) error`. Please see https://gorm.io/docs/hooks.html", schema, cbName, cbName) | 				logger.Default.Warn(context.Background(), "Model %v don't match %vInterface, should be `%v(*gorm.DB) error`. Please see https://gorm.io/docs/hooks.html", schema, cbName, cbName) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 demoManito
						demoManito