Skip to content

Relationship validation of object/array #335

Closed
@dklesev

Description

@dklesev

Example: An Owner can have many Pets. A Pet has only one Owner.

But if I try to send invalid PATCH (array of Owners):

{
    "data": {
        "type": "pets",
        "id": "1",
        "attributes": {
            "someValue": true
        },
        "relationships": {
            "owner": {
                "data": [{
                    "type": "owners",
                    "id": "1"
                }]
            }
        } 
    }
}

(Type member is not a string, or is empty. at /var/www/vendor/cloudcreativity/laravel-json-api/src/Object/IdentifiableTrait.php:47)

or an invalid PATCH (Pet object)

{
    "data": {
        "type": "owners",
        "id": "1",
        "attributes": {
            "someValue": true
        },
        "relationships": {
            "pets": {
                "data": {
                    "type": "pets",
                    "id": "1"
                }
            }
        } 
    }
}

(Argument 1 passed to CloudCreativity\LaravelJsonApi\Object\ResourceIdentifier::fromArray() must be of the type array, string given)

I get an HTTP 500 (see errors above).

How or where to check if relationship is a valid Array (HasMany) or object (HasOne)?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions