@@ -689,6 +689,41 @@ func TestUnmarshalRelationships(t *testing.T) {
689
689
}
690
690
}
691
691
692
+ func TestUnmarshalMany_relationships_with_circular_inclusion (t * testing.T ) {
693
+ data := samplePayloadWithCircularInclusion ()
694
+ payload , err := json .Marshal (data )
695
+ if err != nil {
696
+ t .Fatal (err )
697
+ }
698
+ in := bytes .NewReader (payload )
699
+ model := reflect .TypeOf (new (Blog ))
700
+
701
+ out , err := UnmarshalManyPayload (in , model )
702
+ if err != nil {
703
+ t .Fatal (err )
704
+ }
705
+
706
+ result_1 := out [0 ].(* Blog )
707
+
708
+ if result_1 .Project != result_1 .Organization .DefaultProject {
709
+ t .Errorf ("expected blog.project (%p) to hold the same pointer as blog.organization.default-project (%p) " , result_1 .Project , result_1 .Organization .DefaultProject )
710
+ }
711
+
712
+ if result_1 .Organization != result_1 .Project .Organization {
713
+ t .Errorf ("expected blog.organization (%p) to hold the same pointer as blog.project.organization (%p)" , result_1 .Organization , result_1 .Project .Organization )
714
+ }
715
+
716
+ result_2 := out [1 ].(* Blog )
717
+
718
+ if result_2 .Project != result_2 .Organization .DefaultProject {
719
+ t .Errorf ("expected blog.project (%p) to hold the same pointer as blog.organization.default-project (%p) " , result_2 .Project , result_2 .Organization .DefaultProject )
720
+ }
721
+
722
+ if result_2 .Organization != result_2 .Project .Organization {
723
+ t .Errorf ("expected blog.organization (%p) to hold the same pointer as blog.project.organization (%p)" , result_2 .Organization , result_2 .Project .Organization )
724
+ }
725
+ }
726
+
692
727
func Test_UnmarshalPayload_polymorphicRelations (t * testing.T ) {
693
728
in := bytes .NewReader ([]byte (`{
694
729
"data": {
@@ -1378,6 +1413,105 @@ func TestUnmarshalCustomTypeAttributes_ErrInvalidType(t *testing.T) {
1378
1413
}
1379
1414
}
1380
1415
1416
+ func samplePayloadWithCircularInclusion () * ManyPayload {
1417
+ payload := & ManyPayload {
1418
+ Data : []* Node {
1419
+ {
1420
+ Type : "blogs" ,
1421
+ ClientID : "1" ,
1422
+ ID : "1" ,
1423
+ Attributes : map [string ]interface {}{
1424
+ "title" : "Foo" ,
1425
+ "current_post_id" : 1 ,
1426
+ "created_at" : 1436216820 ,
1427
+ "view_count" : 1000 ,
1428
+ },
1429
+ Relationships : map [string ]interface {}{
1430
+ "project" : & RelationshipOneNode {
1431
+ Data : & Node {
1432
+ Type : "projects" ,
1433
+ ClientID : "1" ,
1434
+ ID : "1" ,
1435
+ },
1436
+ },
1437
+ "organization" : & RelationshipOneNode {
1438
+ Data : & Node {
1439
+ Type : "organizations" ,
1440
+ ClientID : "1" ,
1441
+ ID : "1" ,
1442
+ },
1443
+ },
1444
+ },
1445
+ },
1446
+ {
1447
+ Type : "blogs" ,
1448
+ ClientID : "2" ,
1449
+ ID : "2" ,
1450
+ Attributes : map [string ]interface {}{
1451
+ "title" : "Foo2" ,
1452
+ "current_post_id" : 1 ,
1453
+ "created_at" : 1436216820 ,
1454
+ "view_count" : 1000 ,
1455
+ },
1456
+ Relationships : map [string ]interface {}{
1457
+ "project" : & RelationshipOneNode {
1458
+ Data : & Node {
1459
+ Type : "projects" ,
1460
+ ClientID : "1" ,
1461
+ ID : "1" ,
1462
+ },
1463
+ },
1464
+ "organization" : & RelationshipOneNode {
1465
+ Data : & Node {
1466
+ Type : "organizations" ,
1467
+ ClientID : "1" ,
1468
+ ID : "1" ,
1469
+ },
1470
+ },
1471
+ },
1472
+ },
1473
+ },
1474
+ Included : []* Node {
1475
+ {
1476
+ Type : "projects" ,
1477
+ ClientID : "1" ,
1478
+ ID : "1" ,
1479
+ Attributes : map [string ]interface {}{
1480
+ "name" : "Bar" ,
1481
+ },
1482
+ Relationships : map [string ]interface {}{
1483
+ "organization" : & RelationshipOneNode {
1484
+ Data : & Node {
1485
+ Type : "organizations" ,
1486
+ ClientID : "1" ,
1487
+ ID : "1" ,
1488
+ },
1489
+ },
1490
+ },
1491
+ },
1492
+ {
1493
+ Type : "organizations" ,
1494
+ ClientID : "1" ,
1495
+ ID : "1" ,
1496
+ Attributes : map [string ]interface {}{
1497
+ "name" : "Baz" ,
1498
+ },
1499
+ Relationships : map [string ]interface {}{
1500
+ "default_project" : & RelationshipOneNode {
1501
+ Data : & Node {
1502
+ Type : "projects" ,
1503
+ ClientID : "1" ,
1504
+ ID : "1" ,
1505
+ },
1506
+ },
1507
+ },
1508
+ },
1509
+ },
1510
+ }
1511
+
1512
+ return payload
1513
+ }
1514
+
1381
1515
func samplePayloadWithoutIncluded () map [string ]interface {} {
1382
1516
return map [string ]interface {}{
1383
1517
"data" : map [string ]interface {}{
0 commit comments