Description
I have four schemas:
class LikeSchema extends Schema
{
protected int $maxDepth = 4;
public function fields(): array
{
return [
ID::make(),
Str::make('userId'),
MorphTo::make('likeable', 'likeable')
->types('contents', 'products'),
];
}
}
class ContentSchema extends Schema
{
public function fields(): array
{
return [
ID::make(),
Str::make('title'),
HasMany::make('likes')->type('likes'),
MorphTo::make('contentable', 'contentable')
->types('articles', 'videos'),
];
}
}
class ArticleSchema extends Schema
{
public function fields(): array
{
return [
ID::make(),
Str::make('body'),
HasOne::make('content', 'content'),
];
}
}
class VideoSchema extends Schema
{
public function fields(): array
{
return [
ID::make(),
HasOne::make('content', 'content'),
HasMany::make('media'),
];
}
}
I need to get the videos.media
relationship via the likes
resource, so I'm trying to do the following query:
GET localhost/api/v1/likes?include=likeable.contentable.media
but I get the error “Include path likeable.contentable.media is not allowed.”
.
At the same time, if I want to get the videos.media
relation via the contents
resource, I make the following request:
GET localhost/api/v1/contents?include=contentable.media
and it works as it should!
At first, I thought it was the depth of the relationship, but changing the $maxDepth
property in LikeSchema
didn't work.
Moreover, if you try to replace MorphTo relationships (likes.likeable
, contents.contentable
) with any other ones, for example BelongsTo, everything works correctly.
The problem is in the MorphTo relation; After the second MorphTo relation in the include chain, the next relations in the chain do not want to be loaded.