Frage

I have this database structure:

  • Comments
  • DocTypes
  • Papers
  • Videos
  • Discussions

The users can make comments on one those 3 doc types: paper, video and discussion.

For that, I created 3 types in my DocTypes

id    name
1     paper
2     video
3     discussion

In the Comments table, I have the doc_type_id.

Now, I would like to use the Comment entity and be able to make comments. What is the best practice in this case? Is there a way to do the relations between the Comment and the Paper entity for example, or should I do everything manually: check the type and make a switch case?

Thank you.

War es hilfreich?

Lösung

If I understand you correctly, DocType is a mapped superclass and Paper, Video, Discussion extend it. In that case, you could just add OneToMany relation from DocType to Comment.

This should create a field doctype_id in your comments table referencing doctype table. This is assuming you're using class table inheritance.

You could then just do:

 $paper = $this->getDoctrine()->getRepository('Papers\Class\Here')->find(5238953);
 $paper->getComments();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top