Ask Your Question
2

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

asked 2013-05-28 21:24:10 -0500

pcompassion's avatar

updated 2013-05-28 21:25:16 -0500

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?

edit retag flag offensive close merge delete

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  ( 2013-05-29 00:08:37 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-05-29 00:04:02 -0500

Evgeny's avatar

updated 2013-05-29 00:06:45 -0500

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-28 21:24:10 -0500

Seen: 243 times

Last updated: May 29 '13