问题
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.
回答1:
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:
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.
来源:https://stackoverflow.com/questions/6073617/single-table-inheritance-or-class-table-inheritance