Skip to content

Support validators existing relationships returning objects #391

@lindyhopchris

Description

@lindyhopchris

This:

    /**
     * @param SystemVersion $record
     * @return iterable
     */
    protected function existingRelationships($record): iterable
    {
        return [
            'product-version' => [
                'data' => [
                    'type' => 'product-versions',
                    'id' => (string) $record->productVersion->getRouteKey(),
                ],
            ],
            'system' => [
                'data' => [
                    'type' => 'systems',
                    'id' => (string) $record->system->getRouteKey(),
                ],
            ],
        ];
    }

Could be simplified to this:

    /**
     * @param SystemVersion $record
     * @return iterable
     */
    protected function existingRelationships($record): iterable
    {
        return [
            'product-version' => $record->productVersion,
            'system' => $record->system,
        ];
    }

If the abstract validators class converted objects and null values to a JSON API data array. Would need to support iterables as well (i.e. collections).

Can be implemented in a backwards compatible way if we detect arrays with a data key.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions