@@ -75,18 +75,17 @@ func compareTags(tags []Tag, contents []string) bool {
75
75
}
76
76
77
77
func TestManyToManyWithMultiPrimaryKeys (t * testing.T ) {
78
- t .Skip ()
79
78
if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
80
79
t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
81
80
}
82
81
83
- if name := DB .Dialector .Name (); name == "postgres" {
82
+ if name := DB .Dialector .Name (); name == "postgres" || name == "oracle" {
84
83
stmt := gorm.Statement {DB : DB }
85
84
stmt .Parse (& Blog {})
86
85
stmt .Schema .LookUpField ("ID" ).Unique = true
87
86
stmt .Parse (& Tag {})
88
87
stmt .Schema .LookUpField ("ID" ).Unique = true
89
- // postgers only allow unique constraint matching given keys
88
+ // postgers and oracle only allow unique constraint matching given keys
90
89
}
91
90
92
91
DB .Migrator ().DropTable (& Blog {}, & Tag {}, "blog_tags" , "locale_blog_tags" , "shared_blog_tags" )
@@ -300,7 +299,6 @@ func TestManyToManyWithCustomizedForeignKeys(t *testing.T) {
300
299
}
301
300
302
301
func TestManyToManyWithCustomizedForeignKeys2 (t * testing.T ) {
303
- t .Skip ()
304
302
if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
305
303
t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
306
304
}
@@ -309,6 +307,15 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
309
307
t .Skip ("skip postgres due to it only allow unique constraint matching given keys" )
310
308
}
311
309
310
+ if name := DB .Dialector .Name (); name == "oracle" {
311
+ stmt := gorm.Statement {DB : DB }
312
+ stmt .Parse (& Blog {})
313
+ stmt .Schema .LookUpField ("ID" ).Unique = true
314
+ stmt .Parse (& Tag {})
315
+ stmt .Schema .LookUpField ("ID" ).Unique = true
316
+ // oracle only allow unique constraint matching given keys
317
+ }
318
+
312
319
DB .Migrator ().DropTable (& Blog {}, & Tag {}, "blog_tags" , "locale_blog_tags" , "shared_blog_tags" )
313
320
if err := DB .AutoMigrate (& Blog {}, & Tag {}); err != nil {
314
321
t .Fatalf ("Failed to auto migrate, got error: %v" , err )
@@ -326,7 +333,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
326
333
DB .Save (& blog )
327
334
328
335
blog2 := Blog {
329
- ID : blog . ID ,
336
+ ID : 2 ,
330
337
Locale : "EN" ,
331
338
}
332
339
DB .Create (& blog2 )
@@ -358,7 +365,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
358
365
}
359
366
360
367
var blog1 Blog
361
- DB .Preload ("LocaleTags" ).Find (& blog1 , "locale = ? AND id = ?" , "ZH" , blog .ID )
368
+ DB .Preload ("LocaleTags" ).Find (& blog1 , "\" locale\" = ? AND \" id \" = ?" , "ZH" , blog .ID )
362
369
if ! compareTags (blog1 .LocaleTags , []string {"tag1" , "tag2" , "tag3" }) {
363
370
t .Fatalf ("Preload many2many relations" )
364
371
}
@@ -388,7 +395,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
388
395
}
389
396
390
397
var blog11 Blog
391
- DB .Preload ("LocaleTags" ).First (& blog11 , "id = ? AND locale = ?" , blog .ID , blog .Locale )
398
+ DB .Preload ("LocaleTags" ).First (& blog11 , "\" id \" = ? AND \" locale\" = ?" , blog .ID , blog .Locale )
392
399
if ! compareTags (blog11 .LocaleTags , []string {"tag1" , "tag2" , "tag3" }) {
393
400
t .Fatalf ("CN Blog's tags should not be changed after EN Blog Replace" )
394
401
}
@@ -399,7 +406,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
399
406
}
400
407
401
408
var blog21 Blog
402
- DB .Preload ("LocaleTags" ).First (& blog21 , "id = ? AND locale = ?" , blog2 .ID , blog2 .Locale )
409
+ DB .Preload ("LocaleTags" ).First (& blog21 , "\" id \" = ? AND \" locale\" = ?" , blog2 .ID , blog2 .Locale )
403
410
if ! compareTags (blog21 .LocaleTags , []string {"tag5" , "tag6" }) {
404
411
t .Fatalf ("EN Blog's tags should be changed after Replace" )
405
412
}
@@ -454,8 +461,6 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
454
461
}
455
462
456
463
func TestCompositePrimaryKeysAssociations (t * testing.T ) {
457
- t .Skip ()
458
-
459
464
type Label struct {
460
465
BookID * uint `gorm:"primarykey"`
461
466
Name string `gorm:"primarykey"`
0 commit comments