我有两个实体,Question和Alternative,其中 Question 与 Alternative 有 OneToMany 关系,我正在尝试通过 POST to Question API Platform发送带有Alternative嵌套文档的 JSON 。
API 平台在下面返回该错误:
Nested documents for "alternatives" attribute are not allowed. Use IRIs instead.
Run Code Online (Sandbox Code Playgroud)
搜索它我发现有些人说这只能使用 IRI,而其他一些人说可以使用非规范化和规范化上下文来解决这个问题,但我找不到关于它的一些示例或教程。
TL; 博士;
有没有办法在不使用 IRI 的情况下将嵌套关系发送到 API 平台上的实体 POST 中?
更新:
如所问,请参阅下面的问题和替代实体的两个映射。
题
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\QuestionRepository")
* @ApiResource()
*/
class Question implements CreatedAtEntityInterface, UpdatedAtEntityInterface
{
/**
* …Run Code Online (Sandbox Code Playgroud)