Closed Syfele closed 1 year ago
Hello, have you read https://api-platform.com/docs/admin/handling-relations/?
Hello, have you read https://api-platform.com/docs/admin/handling-relations/?
@alanpoulain : Thanks for replying
Yes I read it, If I'm not mistaken, that's what I m using
My API return Hydra, thats why I should use ReferenceField> with
What you need to use depends of the response of the API (and in particular if your relation is embedded or not). Could you paste a typical response of your API?
What you need to use depends of the response of the API (and in particular if your relation is embedded or not). Could you paste a typical response of your API?
API response : Yes country is embedded in user response
Have you tried using the InputGuesser
for country
? It should work by default.
I have the same error and in select options I have api/countries/id instead of labels
Solution was to use "useEmbedded: false" in dataProvider definition, sorry it was me
In order to use it with useEmbedded: true
you'd need to use dot notation in the source prop:
<ReferenceInput source="country.@id" reference="countries">
<SelectInput label="User country" optionText="label" />
</ReferenceInput>
The fetch request comes from <ReferenceInput>
, and it seems to be using its source
prop to build the URL. If your relations are embedded, then country
is an object instead of an IRI string, and that's why the HTTP request is made to http://localhost/api/[object%20Object]
.
It is a little strange that all this extra research is needed just to make it work with the default settings (useEmbedded: true
).
API Platform version(s) affected: x.y.z It is not about API Platform, it is about admin
Description
User have a ManyToOne relation with country, I can create and show user with country, but in edit form, select are empty by default, and I have error saying
No route found for "GET http://localhost/api/[object%20Object]" (from "http://localhost:3000/")
As in the picture belowHow to reproduce
App.js :
CreateUser.js : ( WORKS FINE)
EditUser.js :
In the edit page, email, firstname and lastname are fulfilled but not country and I have error message : ( WITH the list of countries in it )
Am I missing something ? or whats wrong please ? I have try React admin - Selecting a Foreign Key with no result, It doubling user country option in the select
Additional Context
![Capture d’écran de 2023-05-26 14-08-35](https://github.com/api-platform/admin/assets/45661399/7c9a5b7e-e620-4a2c-87bf-68bef4503574)
Thanks for help