[Question] Schema required for polymorphic relationship
Hi @lindyhopchris, love the package you created.
I am confused about an aspect about Polymorphic To-Many relationships because of the following problem: I have the following schema:
class GeolevelableSchema extends Schema
{
public function fields(): array
{
return [
ID::make(),
MorphToMany::make('geolevels', [
BelongsToMany::make('regions')->type('regions'),
BelongsToMany::make('countries')->type('countries'),
]);
DateTime::make('createdAt')->sortable()->readOnly(),
DateTime::make('updatedAt')->sortable()->readOnly(),
];
}
}
I have created a GeolevelCollectionQuery class as stated in the documentation, but when i access an endpoint like this: DELETE /geolevelable/id/relationships/geolevels it throws this error :
LogicException: No schema for JSON:API resource type geolevels.
Am I supposed to create a special kind of schema for the geolevels "resource" (there are schemas for regions and countries already)? That would be like creating a schema for the "media" type (the Polymorphic To-Many example from the documentation ) - something which makes little sense to me.
Am I missing something?
Thank you for your time!
If there is a schema for the geolevels model, you should register it in your Server.php.
Well sure, but there is no geolevels model because it's just a name to group countries and regions under a single relationship, just like media in the documentation.
I'm on holiday at the moment so can't look into this in detail. What's the stack trace of that exception? Wondering where it is being thrown from.
Hi, sorry for the delay, I've also been away on holiday. Here is a stack trace for the problem. Unfortunately, PHPUnit did not provide the stack trace for this so i uploaded a photo taken while using the debugger.

Hello @lindyhopchris, have you got any time to take a look at this?
I haven't unfortunately - extremely limited on open source time at the moment.
Just looking at your original post, you've called the class GeolevelableSchema. But it's probably looking for GeolevelSchema. Does that fix it?