Scan value into ignored fields if there is no ambiguity
This commit is contained in:
		
							parent
							
								
									8ee49893d1
								
							
						
					
					
						commit
						341703ed5d
					
				
							
								
								
									
										10
									
								
								field.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								field.go
									
									
									
									
									
								
							@ -62,10 +62,12 @@ func (scope *Scope) Fields() map[string]*Field {
 | 
				
			|||||||
		indirectValue := scope.IndirectValue()
 | 
							indirectValue := scope.IndirectValue()
 | 
				
			||||||
		isStruct := indirectValue.Kind() == reflect.Struct
 | 
							isStruct := indirectValue.Kind() == reflect.Struct
 | 
				
			||||||
		for _, structField := range modelStruct.StructFields {
 | 
							for _, structField := range modelStruct.StructFields {
 | 
				
			||||||
			if isStruct {
 | 
								if field, ok := fields[structField.DBName]; !ok || field.IsIgnored {
 | 
				
			||||||
				fields[structField.DBName] = getField(indirectValue, structField)
 | 
									if isStruct {
 | 
				
			||||||
			} else {
 | 
										fields[structField.DBName] = getField(indirectValue, structField)
 | 
				
			||||||
				fields[structField.DBName] = &Field{StructField: structField, IsBlank: true}
 | 
									} else {
 | 
				
			||||||
 | 
										fields[structField.DBName] = &Field{StructField: structField, IsBlank: true}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -149,24 +149,25 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if fieldStruct.Tag.Get("sql") == "-" {
 | 
								if fieldStruct.Tag.Get("sql") == "-" {
 | 
				
			||||||
				field.IsIgnored = true
 | 
									field.IsIgnored = true
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				sqlSettings := parseTagSetting(field.Tag.Get("sql"))
 | 
					 | 
				
			||||||
				gormSettings := parseTagSetting(field.Tag.Get("gorm"))
 | 
					 | 
				
			||||||
				if _, ok := gormSettings["PRIMARY_KEY"]; ok {
 | 
					 | 
				
			||||||
					field.IsPrimaryKey = true
 | 
					 | 
				
			||||||
					modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, field)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if _, ok := sqlSettings["DEFAULT"]; ok {
 | 
					 | 
				
			||||||
					field.HasDefaultValue = true
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if value, ok := gormSettings["COLUMN"]; ok {
 | 
					 | 
				
			||||||
					field.DBName = value
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					field.DBName = ToDBName(fieldStruct.Name)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sqlSettings := parseTagSetting(field.Tag.Get("sql"))
 | 
				
			||||||
 | 
								gormSettings := parseTagSetting(field.Tag.Get("gorm"))
 | 
				
			||||||
 | 
								if _, ok := gormSettings["PRIMARY_KEY"]; ok {
 | 
				
			||||||
 | 
									field.IsPrimaryKey = true
 | 
				
			||||||
 | 
									modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, field)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if _, ok := sqlSettings["DEFAULT"]; ok {
 | 
				
			||||||
 | 
									field.HasDefaultValue = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if value, ok := gormSettings["COLUMN"]; ok {
 | 
				
			||||||
 | 
									field.DBName = value
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									field.DBName = ToDBName(fieldStruct.Name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			fields = append(fields, field)
 | 
								fields = append(fields, field)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user