Single Table Inheritance or Class Table Inheritance?
Asked Answered
M

2

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.

Miscarry answered 20/5, 2011 at 14:45 Comment(0)
C
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

Campinas answered 20/5, 2011 at 15:32 Comment(2)
Also, another link that yours lead me to was peterhamilton.github.com/citier which has lots of blog links about this. Thank you.Miscarry
@Miscarry There isn't a GitHub Pages site here.Sawfly
B
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.

Baton answered 24/1, 2018 at 22:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.