放置请求实体链接到其他实体symfony

时间:2019-06-13 12:56:26

标签: rest api symfony put

我陷入了困境:我必须拥有实体ProfileJob 在Job实体中,我有:

/**
     * @var string
     * @Gedmo\Translatable
     * @ORM\Column(name="label", type="string", length=255)
     * @Serializer\Groups({"profile_details","profile_put"})
     * @Serializer\Type("string")
     * @Serializer\Expose()
     */
    private $label;

在个人资料实体中,我有:

     * @var Job
     *
     * @Assert\NotBlank(message="app.profile.job.not_blank")
     * @ORM\ManyToOne(targetEntity="App\Entity\Job")
     * @ORM\JoinColumn(name="job_id", referencedColumnName="id")
     * @Serializer\Groups({"profile_details","user_details","corporate_details","profile_put"})
     * @Serializer\Type("App\Entity\Job")
     * @Serializer\Expose()
     */
    private $job;

    /**
     * @return Job
     */
    public function getJob(): Job
    {
        return $this->job;
    }

    /**
     * @param Job $job
     *
     * @return Profile
     */
    public function setJob(Job $job): Profile
    {
        $this->job = $job;

        return $this;
    }

编辑: 在控制器中:

public function putAction(Request $request, Profile $profile): Profile
    {
        $profile
                ->setJob($request->get('job'))

        $errors = $this->validator->validate($profile);
        if (count($errors) > 0) {
            throw new UnprocessableEntityHttpException((string) $errors);
        }
        $this->entityManager->persist($profile);
        $this->entityManager->flush();

        return $profile;
    }

我正在尝试在Profile实体上执行放置操作,以更改某些常规string字段。我不知道如何在邮递员上设置放置请求的正文,我尝试只放置标签,但得到了"Argument 1 passed to App\\Entity\\Profile::setJob() must be an instance of App\\Entity\\Job, array given, called in /srv/api/src/Controller/ProfileController.php on line 114"

0 个答案:

没有答案