Даны три сущности Doctrine.
Ответы на вопросы анкеты Answer
:
/**
* @ORM\Entity(repositoryClass="App\Repository\AnswerRepository")
*/
class Answer
{
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Options", inversedBy="answers")
* @ORM\JoinColumn(nullable=true)
*/
private $options;
public function getOptions(): ?options
{
return $this->options;
}
public function setOptions(?options $options): self
{
$this->options = $options;
return $this;
}
// ...
}
Варианты ответов на вопросы анкеты Options
:
class Options
{
/**
* @ORM\OneToMany(targetEntity="App\Entity\Answer", mappedBy="options")
*/
private $answers;
public function __construct()
{
$this->answers = new ArrayCollection();
}
/**
* @return Collection|Answer[]
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
$answer->setOptions($this);
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
if ($this->answers->contains($answer)) {
$this->answers->removeElement($answer);
// set the owning side to null (unless already changed)
if ($answer->getOptions() === $this) {
$answer->setOptions(null);
}
}
return $this;
}
// ...
}
И сущность с вопросами анкеты Question.
Отправляю POST-запрос с ID вариантов ответов на вопросы анкеты:
{
"options": [
"1",
"2"
],
}
Таким образом:
$answer = new Answer();
$form = $this->createFormBuilder($answer)
->add('options', EntityType::class, [
'class' => Options::class,
'multiple' => true
]);
Получают ответ:
{
"code": 500,
"message": "Expected argument of type \"App\\Entity\\Options or null\", \"Doctrine\\Common\\Collections\\ArrayCollection\" given at property path \"options\"."
}
Помогите!