-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Included morph to many data is null
#280
Comments
Could be related to #164 |
Additional research; I did try to refactor the |
I did a deep-dive in the package code. Here I try to address the point where I think it goes wrong. Within the Because the At this point we enter the And in the end, the I don't know how to solve this issue, but I hope this deep-dive helps debugging the issue @lindyhopchris. |
Alright! I've found the actual problem! Because there is no equivalent relationship type for JSON:API Only this extended As a workaround, you could directly instantiate an extended public function relationships($request): iterable
{
return [
$this->relation('owner'),
$this->relation('tags'),
new \LaravelJsonApi\Eloquent\Resources\Relation(
$this->resource,
$this->selfUrl(),
$this->schema->relationship('texts'),
),
];
} In my opinion, the Let me know what you think! At least I have a temporary workaround for now. |
Thanks for the explanation with this. I think this is another example why actually I think it's a bad idea to allow people to use the Resource class directly. A lot of the implementation relies on what we've implemented. Over time I want to get rid of the need to do that, and ensure that everything a developer needs to do can be done via the schema. |
The use case is, I've a
Round
that has manyTextOverrides
and belongs to manyDefaultTexts
. Within theRoundSchema
I've added the following field:When I navigate to
http://localhost/api/v1/rounds/1/texts
, I see bothdefault-texts
andtext-overrides
nicely listed. But when I try to includetexts
, usinghttp://localhost/api/v1/rounds/1?include=texts
, I get the following exception message:This exception message is displayed because we prevent accessing missing attributes using;
Model::preventAccessingMissingAttributes();
. When I remove this line the view round API endpoint loads, but has the following outcome. Thedata
isnull
which is incorrect because there aredefault-texts
andtext-overrides
.I do have added a
TextCollectionQuery
, which extends theResourceQuery
, and registered in theserving
method of theServer
class, as described on the documentation page; https://laraveljsonapi.io/docs/3.0/digging-deeper/polymorphic-to-many.html#query-parameters.At this point I've no idea what's wrong with the implementation. What am I missing?
The text was updated successfully, but these errors were encountered: