fix: relation field returning
This commit is contained in:
		
							parent
							
								
									f91313436a
								
							
						
					
					
						commit
						cd405c238d
					
				@ -230,7 +230,7 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, field := range schema.Fields {
 | 
						for _, field := range schema.Fields {
 | 
				
			||||||
		if field.HasDefaultValue && field.DefaultValueInterface == nil {
 | 
							if field.DataType != "" && field.HasDefaultValue && field.DefaultValueInterface == nil {
 | 
				
			||||||
			schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field)
 | 
								schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ package tests_test
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gorm.io/gorm"
 | 
				
			||||||
	. "gorm.io/gorm/utils/tests"
 | 
						. "gorm.io/gorm/utils/tests"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -224,3 +225,29 @@ func TestBelongsToAssociationForSlice(t *testing.T) {
 | 
				
			|||||||
	AssertAssociationCount(t, users[0], "Company", 0, "After Delete")
 | 
						AssertAssociationCount(t, users[0], "Company", 0, "After Delete")
 | 
				
			||||||
	AssertAssociationCount(t, users[1], "Company", 1, "After other user Delete")
 | 
						AssertAssociationCount(t, users[1], "Company", 1, "After other user Delete")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBelongsToDefaultValue(t *testing.T) {
 | 
				
			||||||
 | 
						type Org struct {
 | 
				
			||||||
 | 
							ID string
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						type BelongsToUser struct {
 | 
				
			||||||
 | 
							OrgID string
 | 
				
			||||||
 | 
							Org   Org `gorm:"default:NULL"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tx := DB.Session(&gorm.Session{})
 | 
				
			||||||
 | 
						tx.Config.DisableForeignKeyConstraintWhenMigrating = true
 | 
				
			||||||
 | 
						AssertEqual(t, DB.Config.DisableForeignKeyConstraintWhenMigrating, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tx.Migrator().DropTable(&BelongsToUser{}, &Org{})
 | 
				
			||||||
 | 
						tx.AutoMigrate(&BelongsToUser{}, &Org{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						user := &BelongsToUser{
 | 
				
			||||||
 | 
							Org: Org{
 | 
				
			||||||
 | 
								ID: "BelongsToUser_Org_1",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err := DB.Create(&user).Error
 | 
				
			||||||
 | 
						AssertEqual(t, err, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user