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

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

Closed
cedriclombardot opened this issue Apr 8, 2021 · 2 comments
Closed

Comments

@cedriclombardot
Copy link

cedriclombardot commented Apr 8, 2021

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
Copy link
Member

Is this PR helping you? api-platform/docs#1144

@cedriclombardot
Copy link
Author

@alanpoulain Thanks a lot !!!!!!

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