@@ -75,18 +75,17 @@ func compareTags(tags []Tag, contents []string) bool {
7575}
7676
7777func TestManyToManyWithMultiPrimaryKeys (t * testing.T ) {
78- t .Skip ()
7978 if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
8079 t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
8180 }
8281
83- if name := DB .Dialector .Name (); name == "postgres" {
82+ if name := DB .Dialector .Name (); name == "postgres" || name == "oracle" {
8483 stmt := gorm.Statement {DB : DB }
8584 stmt .Parse (& Blog {})
8685 stmt .Schema .LookUpField ("ID" ).Unique = true
8786 stmt .Parse (& Tag {})
8887 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
9089 }
9190
9291 DB .Migrator ().DropTable (& Blog {}, & Tag {}, "blog_tags" , "locale_blog_tags" , "shared_blog_tags" )
@@ -300,7 +299,6 @@ func TestManyToManyWithCustomizedForeignKeys(t *testing.T) {
300299}
301300
302301func TestManyToManyWithCustomizedForeignKeys2 (t * testing.T ) {
303- t .Skip ()
304302 if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
305303 t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
306304 }
@@ -309,6 +307,15 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
309307 t .Skip ("skip postgres due to it only allow unique constraint matching given keys" )
310308 }
311309
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+
312319 DB .Migrator ().DropTable (& Blog {}, & Tag {}, "blog_tags" , "locale_blog_tags" , "shared_blog_tags" )
313320 if err := DB .AutoMigrate (& Blog {}, & Tag {}); err != nil {
314321 t .Fatalf ("Failed to auto migrate, got error: %v" , err )
@@ -326,7 +333,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
326333 DB .Save (& blog )
327334
328335 blog2 := Blog {
329- ID : blog . ID ,
336+ ID : 2 ,
330337 Locale : "EN" ,
331338 }
332339 DB .Create (& blog2 )
@@ -358,7 +365,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
358365 }
359366
360367 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 )
362369 if ! compareTags (blog1 .LocaleTags , []string {"tag1" , "tag2" , "tag3" }) {
363370 t .Fatalf ("Preload many2many relations" )
364371 }
@@ -388,7 +395,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
388395 }
389396
390397 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 )
392399 if ! compareTags (blog11 .LocaleTags , []string {"tag1" , "tag2" , "tag3" }) {
393400 t .Fatalf ("CN Blog's tags should not be changed after EN Blog Replace" )
394401 }
@@ -399,7 +406,7 @@ func TestManyToManyWithCustomizedForeignKeys2(t *testing.T) {
399406 }
400407
401408 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 )
403410 if ! compareTags (blog21 .LocaleTags , []string {"tag5" , "tag6" }) {
404411 t .Fatalf ("EN Blog's tags should be changed after Replace" )
405412 }
0 commit comments