我的疑问是关于 Api 平台的。( https://api-platform.com ) 我有两个实体。问题和答案。我想要进行一次 POST 调用来创建一个只有一个答案的问题。我展示我的实体。
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* normalizationContext={"groups"={"question"}},
* denormalizationContext={"groups"={"question"}})
* @ORM\Entity
*/
class Question
{
/**
* @Groups({"question"})
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Groups({"question"})
* @ORM\Column
* @Assert\NotBlank
*/
public $name = '';
/**
* @Groups({"question"})
* @ORM\OneToMany(targetEntity="Answer", mappedBy="question", cascade={"persist"})
*/
private $answers;
public function getAnswers()
{
return $this->answers;
}
public function …Run Code Online (Sandbox Code Playgroud)