Answer the question
In order to leave comments, you need to log in
How to create a dependency in tables?
Good day.
Help put things in order. I have entities like "Question" and "Answer".
How to properly store them in tables?
Question
- id
- text
Answer
- id
- text
- id_question
- right
Should I create an intermediate table like:?
question_answer
- id_question
- id_answer
- right
Then the fields id_question and right are removed from the Answer table
Answer the question
In order to leave comments, you need to log in
Read about relationships: 1 to one, 1 to many. many to many.
The question_answer table is needed for the M-M connection, that is, when one question has many answers and one answer can belong to many questions. Apparently, this is not what you need, your question-answer is 1-M, that is, there are many answers to one question, but one answer is always only one question. Communication 1-M is done as you have in the first option.
If the same Answer can be the answer to several questions, then it is better with an intermediate one.
Universal scheme:
obect: id
parent object: parent_id
Total:
add the parent_id column to the required table and get any link structure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question