@@ -172,132 +172,6 @@ func TestManyToManyWithMultiPrimaryKeys(t *testing.T) {
172
172
}
173
173
}
174
174
175
- func TestManyToManyWithCustomizedForeignKeys (t * testing.T ) {
176
- t .Skip ()
177
- if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
178
- t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
179
- }
180
-
181
- if name := DB .Dialector .Name (); name == "postgres" {
182
- t .Skip ("skip postgres due to it only allow unique constraint matching given keys" )
183
- }
184
-
185
- DB .Migrator ().DropTable (& Blog {}, & Tag {}, "blog_tags" , "locale_blog_tags" , "shared_blog_tags" )
186
- if err := DB .AutoMigrate (& Blog {}, & Tag {}); err != nil {
187
- t .Fatalf ("Failed to auto migrate, got error: %v" , err )
188
- }
189
-
190
- blog := Blog {
191
- Locale : "ZH" ,
192
- Subject : "subject" ,
193
- Body : "body" ,
194
- SharedTags : []Tag {
195
- {Locale : "ZH" , Value : "tag1" },
196
- {Locale : "ZH" , Value : "tag2" },
197
- },
198
- }
199
- DB .Save (& blog )
200
-
201
- blog2 := Blog {
202
- ID : blog .ID ,
203
- Locale : "EN" ,
204
- }
205
- DB .Create (& blog2 )
206
-
207
- if ! compareTags (blog .SharedTags , []string {"tag1" , "tag2" }) {
208
- t .Fatalf ("Blog should has two tags" )
209
- }
210
-
211
- // Append
212
- tag3 := & Tag {Locale : "ZH" , Value : "tag3" }
213
- DB .Model (& blog ).Association ("SharedTags" ).Append ([]* Tag {tag3 })
214
- if ! compareTags (blog .SharedTags , []string {"tag1" , "tag2" , "tag3" }) {
215
- t .Fatalf ("Blog should has three tags after Append" )
216
- }
217
-
218
- if DB .Model (& blog ).Association ("SharedTags" ).Count () != 3 {
219
- t .Fatalf ("Blog should has three tags after Append" )
220
- }
221
-
222
- if DB .Model (& blog2 ).Association ("SharedTags" ).Count () != 3 {
223
- t .Fatalf ("Blog should has three tags after Append" )
224
- }
225
-
226
- var tags []Tag
227
- DB .Model (& blog ).Association ("SharedTags" ).Find (& tags )
228
- if ! compareTags (tags , []string {"tag1" , "tag2" , "tag3" }) {
229
- t .Fatalf ("Should find 3 tags" )
230
- }
231
-
232
- DB .Model (& blog2 ).Association ("SharedTags" ).Find (& tags )
233
- if ! compareTags (tags , []string {"tag1" , "tag2" , "tag3" }) {
234
- t .Fatalf ("Should find 3 tags" )
235
- }
236
-
237
- var blog1 Blog
238
- DB .Preload ("SharedTags" ).Find (& blog1 )
239
- if ! compareTags (blog1 .SharedTags , []string {"tag1" , "tag2" , "tag3" }) {
240
- t .Fatalf ("Preload many2many relations" )
241
- }
242
-
243
- tag4 := & Tag {Locale : "ZH" , Value : "tag4" }
244
- DB .Model (& blog2 ).Association ("SharedTags" ).Append (tag4 )
245
-
246
- DB .Model (& blog ).Association ("SharedTags" ).Find (& tags )
247
- if ! compareTags (tags , []string {"tag1" , "tag2" , "tag3" , "tag4" }) {
248
- t .Fatalf ("Should find 3 tags" )
249
- }
250
-
251
- DB .Model (& blog2 ).Association ("SharedTags" ).Find (& tags )
252
- if ! compareTags (tags , []string {"tag1" , "tag2" , "tag3" , "tag4" }) {
253
- t .Fatalf ("Should find 3 tags" )
254
- }
255
-
256
- // Replace
257
- tag5 := & Tag {Locale : "ZH" , Value : "tag5" }
258
- tag6 := & Tag {Locale : "ZH" , Value : "tag6" }
259
- DB .Model (& blog2 ).Association ("SharedTags" ).Replace (tag5 , tag6 )
260
- var tags2 []Tag
261
- DB .Model (& blog ).Association ("SharedTags" ).Find (& tags2 )
262
- if ! compareTags (tags2 , []string {"tag5" , "tag6" }) {
263
- t .Fatalf ("Should find 2 tags after Replace" )
264
- }
265
-
266
- DB .Model (& blog2 ).Association ("SharedTags" ).Find (& tags2 )
267
- if ! compareTags (tags2 , []string {"tag5" , "tag6" }) {
268
- t .Fatalf ("Should find 2 tags after Replace" )
269
- }
270
-
271
- if DB .Model (& blog ).Association ("SharedTags" ).Count () != 2 {
272
- t .Fatalf ("Blog should has three tags after Replace" )
273
- }
274
-
275
- // Delete
276
- DB .Model (& blog ).Association ("SharedTags" ).Delete (tag5 )
277
- var tags3 []Tag
278
- DB .Model (& blog ).Association ("SharedTags" ).Find (& tags3 )
279
- if ! compareTags (tags3 , []string {"tag6" }) {
280
- t .Fatalf ("Should find 1 tags after Delete" )
281
- }
282
-
283
- if DB .Model (& blog ).Association ("SharedTags" ).Count () != 1 {
284
- t .Fatalf ("Blog should has three tags after Delete" )
285
- }
286
-
287
- DB .Model (& blog2 ).Association ("SharedTags" ).Delete (tag3 )
288
- var tags4 []Tag
289
- DB .Model (& blog ).Association ("SharedTags" ).Find (& tags4 )
290
- if ! compareTags (tags4 , []string {"tag6" }) {
291
- t .Fatalf ("Tag should not be deleted when Delete with a unrelated tag" )
292
- }
293
-
294
- // Clear
295
- DB .Model (& blog2 ).Association ("SharedTags" ).Clear ()
296
- if DB .Model (& blog ).Association ("SharedTags" ).Count () != 0 {
297
- t .Fatalf ("All tags should be cleared" )
298
- }
299
- }
300
-
301
175
func TestManyToManyWithCustomizedForeignKeys2 (t * testing.T ) {
302
176
if name := DB .Dialector .Name (); name == "sqlite" || name == "sqlserver" {
303
177
t .Skip ("skip sqlite, sqlserver due to it doesn't support multiple primary keys with auto increment" )
0 commit comments