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

Cannot pass an IRI in JSON for a constructor parameter #2036

Closed
guillaume-perreal opened this issue Jun 20, 2018 · 1 comment
Closed

Cannot pass an IRI in JSON for a constructor parameter #2036

guillaume-perreal opened this issue Jun 20, 2018 · 1 comment

Comments

@guillaume-perreal
Copy link

When an object constructor accepts an object that is actually a relation, api-platform/core 2.2.6 fails to denormalize it from an IRI.

e.g. Given this following class, where any Item must be associated to a Project:

/**
 * @ORM\Entity
 * @API\ApiResource
 */
class Item {
  /**
   * @var UuidInterface
   * @ORM\Id
   * @ORM\Column(type="uuid")
   * @Assert\Uuid(strict=true)
   */
  private $id;

  /**
   * @var Project
   * @ORM\ManyToOne(targetEntity=Project::class)
   * @ORM\JoinColumn(nullable=false)
   */
  private $project;

  /* ... More fields ... */

  public constructor(Project $project) {
    $this->id = Uuid::uuid4();
    $this->project = $project;
  }

  /* ... Getters and unicorns ... */
}

The serializer has no issue serializing it. However, it fails to deserialize from the following JSON:

{  "project": "/projects/e00fc841-b090-47da-b67b-9d5b3a73e7ba" }

If I understood the code correctly, the normalizer fails to identify the "project" parameter of the constructor as the "project" association. It waits for a full project and does not even try to fetch an existing project from the database. With a full project, it complains about not being allowed to update (?!).

@teohhanhui
Copy link
Contributor

See #1749

It should be in 2.3

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