Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've got the following tables:

  • Clicks table
  • Websites table
  • Ads table

Both Ads and Websites have many Clicks (i.e. both models have a one-to-many relation with Clicks). In such cases, is it better to use multiple one-to-many relationships, or would a Clickable polymorphic setup be better?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The question you should ask yourself is whether or not a website click is really the same as an ad click. Do they have exactly the same predicates? (other than what type of parent they have) Similarly, when you access click data, will both types often be considered together or are they always treated separately?

The reason that this is important is that you want to draw a distinction between a true subtyping situation and simply having two distinct tables with similar schemas. Someone with a programming background might be tempted to say: "These two things look alike, so they should be like implementations of an Interface." This leads you to a polymorphic design.

However, the considerations for entity subtyping are not quite the same as the considerations for code re-use. If there is no reason to comingle both types of clicks in a single query, then there isn't necessarily a good reason to comingle both types of clicks in a supertype table. There may be a trade-off to be made between a bit of code reuse and keeping your data organized for convenient and logical retrieval.

share|improve this answer
    
Thanks. Even better than an answer to the question is an explanation of the underlying issue. Teach a man to fish... –  BenjaminRH Apr 25 '13 at 12:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.