enable identity column insert optionally for mssql ref: https://github.com/jinzhu/gorm/issues/647

This commit is contained in:
biju-kalissery 2015-09-08 14:04:10 -04:00
parent b71fda1a1a
commit a739f8b035

View File

@ -32,12 +32,23 @@ func TestCustomizeColumn(t *testing.T) {
if scope.PrimaryKey() != col { if scope.PrimaryKey() != col {
t.Errorf("CustomizeColumn should have primary key %s, but got %q", col, scope.PrimaryKey()) t.Errorf("CustomizeColumn should have primary key %s, but got %q", col, scope.PrimaryKey())
} }
tableName := "customize_columns"
idInsRes := DB.EnableIdentityInsert(&DB, tableName)
if idInsRes.Error != nil {
t.Errorf("Error while setting IDENTITY_INSERT ON for table:%v :%v", tableName, idInsRes.Error)
}
expected := "foo" expected := "foo"
cc := CustomizeColumn{ID: 666, Name: expected, Date: time.Now()} cc := CustomizeColumn{ID: 666, Name: expected, Date: time.Now()}
if count := DB.Create(&cc).RowsAffected; count != 1 { res := DB.Create(&cc)
t.Error("There should be one record be affected when create record") if res.Error != nil {
t.Errorf("Error while creating CustomizeColumn:%v", res.Error)
}
if count := res.RowsAffected; count != 1 {
t.Errorf("There should be one record be affected when create record. count:%v", count)
} }
var cc1 CustomizeColumn var cc1 CustomizeColumn