The idea is to design a simple ER diagram for a small application.
The application is a question-answer system. Every user should be able to ask question in text format, and then other users can post answers using image.
At the end, the user who asked the question should be able to select an image to be the correct answer.
So the design that I have so far is that three tables:
- USER with attributes id, username, phone, location, realname, password.
- QUESTION with attributes id, desription, time, status.
- IMAGE with attributes id, address
There are many-to-one relationships between IMAGE and USER and between QUESTION and USER.
However, I don’t know how should the relationship between IMAGE and QUESTION looks like.
Should there be a one-to-one relationship between them? Is that a good design?
Thanks
If the user should be able to select an image to be the correct answer to a question, this implies there should be multiple images available to select – so no, a one-to-one relationship between the two is not a good idea.
If any given image is only ever going to be used in one question, then this would suggest a one-to-many relationship from question to image. If the same image can be used in many questions, then this implies a many-to-many relationship.
Of course, you would need to have a “selected image” attribute on the question table.