Skip to content

Schemas loading for relationships #8

Closed
@phaberest

Description

@phaberest

Hi @lindyhopchris and thanks in advance for this awesome work!
I'm getting an error when I try to add a relationship in my schema, it seems it can't find the schema for the relationship, even if I've set it in the configuration file.

The error I get is

InvalidArgumentException in Parser.php line 241:
Schema is not registered for a resource at path 'addons'.

In json-api.php I set the schemas array as follows

/**
 * Schemas
 */
C::SCHEMAS => [
    Schemas::DEFAULTS => [
        'App\Models\Addon'    => 'App\Schemas\AddonSchema',        // The relationship
        'App\Models\Shipment' => 'App\Schemas\ShipmentSchema',
    ],
    // merged with defaults if JSON API middleware uses the 'extra-schemas' name.
    'extra-schemas' => [
        'User' => 'UserSchema',
    ],
],

And in the parent model schema I have

public function getRelationships(
    $shipment,
    array $includeList = []
) {
    /** @var Shipment $shipment */
    return [
        'addons'   => [
            self::DATA         => $shipment->addons,
            self::SHOW_SELF    => true,
            self::SHOW_RELATED => true
        ],
        'sender'   => [self::DATA => $shipment->sender],
        'receiver' => [self::DATA => $shipment->receiver],
    ];
}

I'm having troubles understanding the docs 100%, maybe I did something wrong. Maybe I'm not including enough from neomerx/json-api...I am jumping from an error to another 😔

Thanks for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions