- See more at: http://blogtimenow.com/blogging/automatically-redirect-blogger-blog-another-blog-website/#sthash.YsVbCxL0.dpuf Journey to Becoming a Web Developer: Single Table Inheritance

Tuesday, February 11, 2014

Single Table Inheritance

I'm currently building an app that needs to have a base model and sub-models. I wasn't sure how to do that, so I did some research online and found STI or Single Table Inheritance.  The idea behind it is that the sub-models will inherit from the base model, so it will be able to use all of the attributes of the base model.  In the migration of the base model you must have a type field. This is how rails knows that other models will be inheriting from this model.  In the example below the singer and dancer models will inherit from the entertainer model, so now we can create a new entertainer object an be able to use the attributes associated with entertainer on that object.










No comments:

Post a Comment