QuestionOrAnswer model?
- by Mark
My site has Listings. Users can ask Questions about listings, and the author of the listing can respond with an Answer. However, the Answer might need clarification, so I've made them recursive (you can "answer" an answer).
So how do I set up the database? The way I have it now looks like this (in Django-style models):
class QuestionOrAnswer(Model):
user = ForeignKey(User, related_name='questions')
listing = ForeignKey(Listing, related_name='questions')
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
message = TextField()
But what bugs me is that listing is now an attribute of the answers as well (it doesn't need to be). What happens if the database gets mangled and an answer belongs to a different listing than its parent question? That just doesn't make any sense. We can separate it with polymorphism:
QuestionOrAnswer
user
message
created
updated
Question(QuestionOrAnswer)
shipment
Answer(QuestionOrAnswer)
parent = ForeignKey(QuestionOrAnswer)
And that ought to work, but now ever question and answer is split into 2 tables. Is it worth this overhead for clearly defined models?