Fix embedded struct with default value, close #3451
This commit is contained in:
		
							parent
							
								
									70a7bd52ca
								
							
						
					
					
						commit
						b8a74a80d7
					
				| @ -345,19 +345,21 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field { | ||||
| 					ef.DBName = prefix + ef.DBName | ||||
| 				} | ||||
| 
 | ||||
| 				if val, ok := ef.TagSettings["PRIMARYKEY"]; ok && utils.CheckTruth(val) { | ||||
| 					ef.PrimaryKey = true | ||||
| 				} else if val, ok := ef.TagSettings["PRIMARY_KEY"]; ok && utils.CheckTruth(val) { | ||||
| 					ef.PrimaryKey = true | ||||
| 				} else { | ||||
| 					ef.PrimaryKey = false | ||||
| 				if ef.PrimaryKey { | ||||
| 					if val, ok := ef.TagSettings["PRIMARYKEY"]; ok && utils.CheckTruth(val) { | ||||
| 						ef.PrimaryKey = true | ||||
| 					} else if val, ok := ef.TagSettings["PRIMARY_KEY"]; ok && utils.CheckTruth(val) { | ||||
| 						ef.PrimaryKey = true | ||||
| 					} else { | ||||
| 						ef.PrimaryKey = false | ||||
| 
 | ||||
| 					if val, ok := ef.TagSettings["AUTOINCREMENT"]; !ok || !utils.CheckTruth(val) { | ||||
| 						ef.AutoIncrement = false | ||||
| 					} | ||||
| 						if val, ok := ef.TagSettings["AUTOINCREMENT"]; !ok || !utils.CheckTruth(val) { | ||||
| 							ef.AutoIncrement = false | ||||
| 						} | ||||
| 
 | ||||
| 					if ef.DefaultValue == "" { | ||||
| 						ef.HasDefaultValue = false | ||||
| 						if ef.DefaultValue == "" { | ||||
| 							ef.HasDefaultValue = false | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
|  | ||||
| @ -9,8 +9,8 @@ require ( | ||||
| 	gorm.io/driver/mysql v1.0.1 | ||||
| 	gorm.io/driver/postgres v1.0.0 | ||||
| 	gorm.io/driver/sqlite v1.1.1 | ||||
| 	gorm.io/driver/sqlserver v1.0.3 | ||||
| 	gorm.io/gorm v1.9.19 | ||||
| 	gorm.io/driver/sqlserver v1.0.4 | ||||
| 	gorm.io/gorm v1.20.0 | ||||
| ) | ||||
| 
 | ||||
| replace gorm.io/gorm => ../ | ||||
|  | ||||
| @ -648,6 +648,7 @@ func TestOffset(t *testing.T) { | ||||
| 	if (len(users1) != len(users4)) || (len(users1)-len(users2) != 3) || (len(users1)-len(users3) != 5) { | ||||
| 		t.Errorf("Offset should work") | ||||
| 	} | ||||
| 
 | ||||
| 	DB.Where("name like ?", "OffsetUser%").Order("age desc").Find(&users1).Offset(3).Find(&users2).Offset(5).Find(&users3).Offset(-1).Find(&users4) | ||||
| 
 | ||||
| 	if (len(users1) != len(users4)) || (len(users1)-len(users2) != 3) || (len(users1)-len(users3) != 5) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu