diff --git a/src/Helpers/DataLinksHelper.php b/src/Helpers/DataLinksHelper.php index c1348a3..7ba0207 100644 --- a/src/Helpers/DataLinksHelper.php +++ b/src/Helpers/DataLinksHelper.php @@ -133,8 +133,8 @@ public static function setResponseDataRelationship(array &$mappings, array &$arr } $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName] = array_filter($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName]); - if (!empty($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName])) { - $data[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyNameKey][] = $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName]; + if (!empty($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName][JsonApiTransformer::DATA_KEY])) { + $data[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyNameKey][JsonApiTransformer::DATA_KEY][] = $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName][JsonApiTransformer::DATA_KEY]; } } } diff --git a/tests/JsonApiTransformerTest.php b/tests/JsonApiTransformerTest.php index 911b5c2..6a51c22 100644 --- a/tests/JsonApiTransformerTest.php +++ b/tests/JsonApiTransformerTest.php @@ -83,14 +83,14 @@ public function testItWillSerializeToJsonApiAComplexObject() "id":"1" } }, - "comments":[ - { - "data":{ - "type":"comment", - "id":"1000" - } - } - ] + "comments": { + "data": [ + { + "type": "comment", + "id": "1000" + } + ] + } } }, "included":[