swisnl / json-api-client

A PHP package for mapping remote {json:api} resources to Eloquent like models and collections.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HasOne relations hydrated by id using ItemHydrator are not correctly serialized

JaZo opened this issue · comments

Detailed description

$itemHydrator = new ItemHydrator(new TypeMapper());

$item = $itemHydrator->hydrate(new ItemWithHasOneRelation(), ['hasone' => 1]);

$item->toJsonApiArray();

Result:

[
    'type' => 'foo-bar',
    'relationships' => [
        'hasone' => [
            'data' => null
        ]
    ]
]

Expected:

[
    'type' => 'foo-bar',
    'relationships' => [
        'hasone' => [
            'data' => [
                'type' => 'foo-baz',
                'id' => 1
            ]
        ]
    ]
]