Поместите объект запроса, связанный с каким-либо другим объектом Symfony. - PullRequest
0 голосов
/ 13 июня 2019

Я застрял на чем-то: у меня есть сущность Profile и Job в сущности 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 поля.Я не знаю, как установить тело запроса put для почтальона, я пытался поставить только метку, но я получил: "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"

...