Closed rekrios closed 3 years ago
Found way #1: Without $_GET's included path, you can set includes through schema's
public function getIncludePaths()
{
return ['relation1.relation11', 'relation2.relation22'];
}
But not convenient for all cases. Maybe someone know's better way
Yeah, polymorphic relationships present a number of problems that I don't think I've ever fully cracked. Think they need some work in future versions of this package to get them working better. Sorry not to be able to provide an immediate fix.
I have similar case in my project. I solved this by defining dummy relations in model to omit error:
trait HasNoneRelations
{
public function __call($method, $parameters)
{
if (in_array($method, $this->getNoneRelations())) {
return $this->belongsToNone();
}
return parent::__call($method, $parameters);
}
public function getNoneRelations(): array
{
return $this->noneRelations ?? [];
}
protected function belongsToNone(): BelongsTo
{
return new BelongsTo($this->newQuery(), $this, '', '', '');
}
}
and then, in model:
class Game extends Model
{
use HasNoneRelations;
protected $noneRelations = [
'attachment',
'attachments',
'reads',
'other-non-existing-relation',
];
}
now you can include through morph relationship :)
I am curious about a more elegant solution.
Closing this in favour of polymorphic relations in the new package - laravel-json-api/laravel
Hi. Is there any easy way to include resources after polymorp(MorphTo) relationship ? Problem: after polymorph relationship different resources have different relationships and you will get fatal with 'method/relationship not found'. I can make eager loading for such resources via
But can't say the same for includes. Maybe there is the way to show them even without them in $_GET path ?