-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicated columns in INSERT SQL for some fields with default value
- Loading branch information
Showing
3 changed files
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,22 @@ func TestDefaultValue(t *testing.T) { | |
} else if result.Name != "foo" || result.Name2 != "foo" || result.Name3 != "" || result.Age != 18 || !result.Enabled || result.Created.Format("20060102") != "20000102" { | ||
t.Fatalf("Failed to find created data with default data, got %+v", result) | ||
} | ||
|
||
type Harumph2 struct { | ||
ID int `gorm:"default:0"` | ||
Email string `gorm:"not null;index:,unique"` | ||
Name string `gorm:"notNull;default:foo"` | ||
Name2 string `gorm:"size:233;not null;default:'foo'"` | ||
Name3 string `gorm:"size:233;notNull;default:''"` | ||
Age int `gorm:"default:18"` | ||
Created time.Time `gorm:"default:2000-01-02"` | ||
Enabled bool `gorm:"default:true"` | ||
} | ||
|
||
harumph2 := Harumph2{ID: 2, Email: "[email protected]"} | ||
if err := DB.Table("harumphs").Create(&harumph2).Error; err != nil { | ||
t.Fatalf("Failed to create data with default value, got error: %v", err) | ||
} else if harumph2.ID != 2 || harumph2.Name != "foo" || harumph2.Name2 != "foo" || harumph2.Name3 != "" || harumph2.Age != 18 || !harumph2.Enabled || harumph2.Created.Format("20060102") != "20000102" { | ||
t.Fatalf("Failed to create data with default value, got: %+v", harumph2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters