Answer the question
In order to leave comments, you need to log in
How to link free answers to a question?
Three Doctrine entities are given.
Answers to the questions of the questionnaireAnswer
:
/**
* @ORM\Entity(repositoryClass="App\Repository\AnswerRepository")
*/
class Answer
{
/**
* @Groups({"answer"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $text;
/**
* @Groups({"answer"})
* @ORM\Column(type="integer", nullable=true)
*/
private $num;
/**
* @Groups({"answer"})
* @ORM\Column(type="boolean", nullable=true)
*/
private $yn;
/**
* @Groups({"answer"})
* @ORM\ManyToMany(targetEntity="App\Entity\Question", inversedBy="answers")
*/
private $question;
/**
* @Groups({"answer"})
* @ORM\ManyToMany(targetEntity="App\Entity\Options", inversedBy="answers")
*/
private $options;
// ...
}
Options
:class Options
{
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Answer", mappedBy="options")
*/
private $answers;
// ...
}
Question
with the questions of the questionnaire ./**
* @ORM\ManyToMany(targetEntity="App\Entity\Answer", mappedBy="question")
*/
private $answers;
{
"text": [
"text",
"another text"
],
"num": [
"",
"1"
],
"yn": [
"",
"1"
],
"options": [
"3",
"2",
"1"
],
"question": [
"1",
"2"
]
}
$answer = new Answer();
$builder
->add('text')
->add('num')
->add('yn')
->add('question')
->add('options')
;
num
, yn
and text
are needed to answer the question if the answer is not prepared in advance ( <input type="text">
). Options
and Question
- there is a connection. Fields num
, yn
and text
(no binding to options
) - no connection. How can they be linked to questions and answers? Now they are simply added to the table Answer
.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question