11

I'm reading about Class Table Inheritance (CTI) and finding I prefer it overall. The question I have is, is there any specific use case for Single Table Inheritance (STI) where you'd use that over CTI?

I read http://rhnh.net/2010/07/02/3-reasons-why-you-should-not-use-single-table-inheritance and as far as I know, it's solid. The use case for STI being a difference in behaviour but not data.

2 Answers 2

6

I would like to point you to a great article I have found that explains with clarity why and when to use CTI. LINK

2
  • 1
    Also, another link that yours lead me to was peterhamilton.github.com/citier which has lots of blog links about this. Thank you.
    – SpaceGhost
    May 20, 2011 at 16:37
  • @SpaceGhost There isn't a GitHub Pages site here.
    – 王奕然
    Aug 14, 2015 at 9:51
0

Use STI for behavior differences like you said. An example I would use would be:

You have Purchase, and you have PartialPurchase, the only difference with data is that when a PartialPurchase is finished, it gets a relation to a newly created Purchase.

So the behavior is different, also, there are cases where I would want PartialPurchase and Purchase to show up in the same query. For a commercial agent, they want to see all of their purchases and partial purchases at the same time so it makes sense for this data to be in the same table. Otherwise, all of the attributes are the same for each model.

In that case I would use STI over CTI.

Though if ever the data started to differ a lot, I would probably create another table that relates to the STI table, and in the case of many differing fields, I would probably think of CTI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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