Skip to content
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

Custom api resource class with "stateOption" and other identifier than "id" throw error "Unable to generate an IRI.." #6705

Open
HrjSnz opened this issue Oct 8, 2024 · 2 comments

Comments

@HrjSnz
Copy link

HrjSnz commented Oct 8, 2024

API Platform version(s) affected: 4.0.3

Description
I use custom resource. In custom resource use stateOption with my entity ORM. If use "id" as identifier so everything works well. On one resource need slug as identifier. So i use ApiProperty and set identifiers. Using default ItemProvider. It can find result without problems. If i dump result in ItemProvider so i can see my result. Problem is in "Unable to generate an IRI for the item of type "App\ApiResource\PageContentApi"", which si crashing in IriConvertor.php line 169.

ApiResource
image

Entity
image

How to reproduce
Simple create custom resource with stateOption to entity. Use native ItemProvider. Change identifier. (In doc see correct slug to uri variable) and run request.

Possible Solution
In IdentifiersExtractor.php method getIdentifiersFromItem() line 51-53. If item is not resource class so there is hardcoded property "id" which get "id" from entity. BUT there should be "slug" i need identifier from apiResource not default ID. If i this part comment (yes comment :D for try what will happen) so its jump next and get correct identifier from operation which is set in custom api resource. And it generate correct uri with ../{slug}

image

Additional Context
Plese fix it.. this is annoying. I love apiPlatform... I think this should work native. Change identifier in custom resource with stateOption. Thanks !!

@HrjSnz
Copy link
Author

HrjSnz commented Nov 14, 2024

Can you someone answer ? I really can not use native providers in custom resource wtih slug identifier because there is hardcoded 'id'.

@soyuka
Copy link
Member

soyuka commented Dec 16, 2024

Hi, sorry I may have missed your issue, my suggestion is to handle your links with https://api-platform.com/docs/guides/handle-links/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants