api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
476 stars 131 forks source link

<ReferenceInput> with EditGuesser not filled or failed to save #373

Closed cedriclombardot closed 3 years ago

cedriclombardot commented 3 years ago

API Platform version(s) affected: "@api-platform/admin": "^2.6.0" and "api-platform/core": "^2.6"

Description

Hi,

We are using ApiPlatform with react-admin and we got a problem, Got this entity and the related on VehicleType

class Formula
{
    /**
     * @var \Ramsey\Uuid\UuidInterface
     *
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class=UuidGenerator::class)
     */
    private $id;
    ....
    /**
     * @ORM\ManyToOne(targetEntity=VehicleType::class, inversedBy="formulas")
     * @ORM\JoinColumn(nullable=false)
     */
    #[Groups([ "read_formula", "write_formula"])]
    private $vehicleType;
    ...
}

On the react side useEmbedded is enabled :

const dataProvider = baseHydraDataProvider(
  entrypoint,
  fetchHydra,
  apiDocumentationParser,
  true // useEmbedded parameter
);

But when i m on FormulaEdit :

const FormulaEdit = (props) => {
  return (
    <EditGuesser {...props}>
      <InputGuesser source="name" />
      <ReferenceInput source="vehicleType" reference="vehicle_types">
        <SelectInput optionText="label" />
      </ReferenceInput>
    </EditGuesser>
  );
};

I got the select but not selected with my db value If i select one value, it well saved. If i use

<ReferenceInput source="vehicleType.@id" reference="vehicle_types">
    <SelectInput optionText="label" />
</ReferenceInput>

The field is filled, but on save i got the error :

hydra:description: "Nested documents for attribute "vehicleType" are not allowed. Use IRIs instead."

What is the good method to deal with relation, in documentation we only found the first method but field is not filled :'(

alanpoulain commented 3 years ago

Is this PR helping you? https://github.com/api-platform/docs/pull/1144

cedriclombardot commented 3 years ago

@alanpoulain Thanks a lot !!!!!!