Fixed: panic on nullable value with multiple foreign key usage (#6839)
See: https://github.com/go-gorm/playground/pull/537
This commit is contained in:
		
							parent
							
								
									8fb9a31775
								
							
						
					
					
						commit
						d81ae6f701
					
				| @ -74,7 +74,11 @@ func ToStringKey(values ...interface{}) string { | |||||||
| 		case uint: | 		case uint: | ||||||
| 			results[idx] = strconv.FormatUint(uint64(v), 10) | 			results[idx] = strconv.FormatUint(uint64(v), 10) | ||||||
| 		default: | 		default: | ||||||
| 			results[idx] = fmt.Sprint(reflect.Indirect(reflect.ValueOf(v)).Interface()) | 			results[idx] = "nil" | ||||||
|  | 			vv := reflect.ValueOf(v) | ||||||
|  | 			if vv.IsValid() && !vv.IsZero() { | ||||||
|  | 				results[idx] = fmt.Sprint(reflect.Indirect(vv).Interface()) | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -48,8 +48,10 @@ func TestToStringKey(t *testing.T) { | |||||||
| 	}{ | 	}{ | ||||||
| 		{[]interface{}{"a"}, "a"}, | 		{[]interface{}{"a"}, "a"}, | ||||||
| 		{[]interface{}{1, 2, 3}, "1_2_3"}, | 		{[]interface{}{1, 2, 3}, "1_2_3"}, | ||||||
|  | 		{[]interface{}{1, nil, 3}, "1_nil_3"}, | ||||||
| 		{[]interface{}{[]interface{}{1, 2, 3}}, "[1 2 3]"}, | 		{[]interface{}{[]interface{}{1, 2, 3}}, "[1 2 3]"}, | ||||||
| 		{[]interface{}{[]interface{}{"1", "2", "3"}}, "[1 2 3]"}, | 		{[]interface{}{[]interface{}{"1", "2", "3"}}, "[1 2 3]"}, | ||||||
|  | 		{[]interface{}{[]interface{}{"1", nil, "3"}}, "[1 <nil> 3]"}, | ||||||
| 	} | 	} | ||||||
| 	for _, c := range cases { | 	for _, c := range cases { | ||||||
| 		if key := ToStringKey(c.values...); key != c.key { | 		if key := ToStringKey(c.values...); key != c.key { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 M Dmitry
						M Dmitry