First time here? Check out the FAQ!
2

what is the relationship between 'thread' and 'question_post'?
 

Thread is a class that holds information that is specific to question_post (not other types of posts)?

Can you give another view/explanation about the relationship between the two?

I'd like to add ManyToMany relationships between question_post to question_post.
Should I make it in Thread or Post?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
pcompassion's avatar
21
pcompassion
asked 11 years ago, updated 11 years ago

Comments

Just to clarify - at the moment we do not have a relation to question_post from Thread, but we actually should.

Evgeny's avatar Evgeny (11 years ago)
see more comments

1 Answer

2

Thread model is there to separate data relevant to the thread as a whole and that of posts. The separation is not always clean - for example votes are duplicated on thread and post.

Thread contains title and tags and post does not, there are some other fields that are only present in the Thread.

All posts used for Q&A have a relation to Thread via a foreign key. Posts of type != either one of 'question', 'answer' or 'comment' may have nulled relation to thread.

Post actually already contains a relation to post - called "parent" - this one is used to associate comments with their parent posts. If you want to add another - it will be necessary to give a unique "related_name".

Another piece is PostRevision, which confusingly does store revision info on tags and titles.

This modeling would be simpler with just Post and PostRevision, but in that case Post would have to carry lot's of fields that would not be used most of the time.

Another consideration for the data modeling is performance: as we have it now - we can load all posts for one thread with one query - by the thread_id and then sort them out into question, answers and comments. Originally we had models Question, Answer and Comment and you can imagine how many more queries were necessary to load data for the question detail page.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 11 years ago, updated 11 years ago
link

Comments

see more comments