R
R
ragnar_ok2019-07-06 00:10:49
MySQL
ragnar_ok, 2019-07-06 00:10:49

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 for answering the questions of the questionnaireOptions :
class Options
{
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Answer", mappedBy="options")
     */
    private $answers;
    // ...
}

And the essence Questionwith the questions of the questionnaire .
/**
     * @ORM\ManyToMany(targetEntity="App\Entity\Answer", mappedBy="question")
     */
    private $answers;

POST request:
{
    "text": [
        "text",
        "another text"
    ],
    "num": [
        "",
        "1"
    ],
    "yn": [
        "",
        "1"
    ],
    "options": [
        "3",
        "2",
        "1"
    ],
    "question": [
        "1",
        "2"
    ]
}

The form:
$answer = new Answer();
        $builder
            ->add('text')
            ->add('num')
            ->add('yn')
            ->add('question')
            ->add('options')
        ;

Database model: 5d1fbba0697d0866391553.png
Fields num, ynand textare needed to answer the question if the answer is not prepared in advance ( <input type="text">).
Optionsand Question- there is a connection. Fields num, ynand 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 question

Ask a Question

731 491 924 answers to any question