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

Using the new entityClass option with a custom provider #5510

Closed
mrossard opened this issue Mar 30, 2023 · 3 comments
Closed

Using the new entityClass option with a custom provider #5510

mrossard opened this issue Mar 30, 2023 · 3 comments

Comments

@mrossard
Copy link
Contributor

API Platform version(s) affected: 3.1.6

Description
I can't get this new option to work as intended while using a custom provider. Either the Get() operation or the GetCollection() is broken.

How to reproduce
https://github.com/mrossard/apip-entityclass

This version gets "The class 'App\ApiResource\DetachedResource' was not found in the chain configured namespaces App\Entity" when you call the Get() operation. Comment the uriVariables: ['id'] and you get `Unable to generate an IRI for the item of type "App\ApiResource\DetachedResource`` on the GetCollection() operation.

Possible Solution
In ApiPlatform\Api\IdentifiersExtractor, if you replace line 136

 throw new RuntimeException('Not able to retrieve identifiers.');

with

return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, $property), $property);

you seem to get the expected result (on the version without the explicit uriVariables).

@soyuka
Copy link
Member

soyuka commented Mar 30, 2023

thanks! I'll try to check your reproducer and see if I can fix it :).

@DartCZ
Copy link
Contributor

DartCZ commented Mar 31, 2023

This solution fixing issue #5502

@SergeyCherenkov
Copy link

If the related entity also has an [ApiResource], then I also get Unable to generate an IRI for the item of type.
api-platform/api-platform#2334 (comment)
This solution works, but it still seems to me that this should not be.

mrossard added a commit to mrossard/core that referenced this issue Apr 20, 2023
soyuka pushed a commit to soyuka/core that referenced this issue Apr 21, 2023
soyuka added a commit that referenced this issue Apr 21, 2023
…building Links (#5550)

* fix: the stateOptions::entityClass should be used when present while building Links
Fixes #5510

* proper fix

---------

Co-authored-by: Manuel Rossard <manuel.rossard@u-bordeaux.fr>
Co-authored-by: soyuka <soyuka@users.noreply.github.com>
soyuka added a commit to api-platform/metadata that referenced this issue Apr 21, 2023
…building Links (#5550)

* fix: the stateOptions::entityClass should be used when present while building Links
Fixes api-platform/core#5510

* proper fix

---------

Co-authored-by: Manuel Rossard <manuel.rossard@u-bordeaux.fr>
Co-authored-by: soyuka <soyuka@users.noreply.github.com>
soyuka added a commit to api-platform/doctrine-orm that referenced this issue Jan 25, 2024
…building Links (#5550)

* fix: the stateOptions::entityClass should be used when present while building Links
Fixes api-platform/core#5510

* proper fix

---------

Co-authored-by: Manuel Rossard <manuel.rossard@u-bordeaux.fr>
Co-authored-by: soyuka <soyuka@users.noreply.github.com>
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

4 participants