-
Notifications
You must be signed in to change notification settings - Fork 43
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
Unable to use MorphTo relationship #222
Comments
@niccolovettorello1997 Have you registered your schema in Server.php ? |
Thanks for raising this issue. Reading it, I feel like I've missed something from the documentation, but it has been a while since I used a morph-to relationship. Can you provided a stack trace for where the |
@atapatel yep, everything is correctly registered. @lindyhopchris sure, here it is: I excluded the first 40 entries that are related to the framework itself, copying only the part that was raised by the package laravel json api. |
Hi @lindyhopchris, do you have any news regarding this problem? Thanks a lot |
Sorry, just not had the time. I believe you need to follow what is explained here when discussing polymorphic to-many relationships, i.e. it's the same issue with polymorphic to-one relations: |
Hello! Particularly, I have a morphTo relation between model A and models B and C. I will call this relation X. What I did:
Yet, when I try a LogicException: No schema for JSON:API resource type X. I do get proper results for a Any suggestion will be appreciated. |
I'm trying create JSON APIs for a model which has a polymorphic
morphTo
relationship. I created the relationship following the documentation (in particular the section onmorphTo
present in this page), but I'm unable to use it correctly. I'll give you further details below.My (simplified) structure is the following:
users
id
name
businesses
id
name
addresses
addressable_type
addressable_id
street_number
A user and a business can have multiple addresses, while a single address is associated either to a user or a business. This is summarized by a
morphTo
polymorphic relationship calledaddressable
and leads to:Addressable.php
Business.php
Same for user
At this point I map the relationship onto the resources' schemas:
BusinessSchema.php
Same for user
AddressSchema.php
Every other detail needed to map this relationship (for example in
AddressRequest.php
, or while defining the routes for addresses, businesses and users) is then filled in correctly. This is reasonably proved by the fact that every other relationship but this (polymorphic) one works fine.Testing the newly implemented API I can create an address, I can modify and then delete it: everything seems to work perfectly.
Nonetheless, while trying to get the related business or user for an address, i.e.
GET 127.0.0.1:8000/v1/addresses/1/addressable
, I get the following error:No schema for JSON:API resource type addressables
I can't figure out what the problem might be.
The text was updated successfully, but these errors were encountered: