Mutiple Table Inheritance (MTI)


MTI is a gem designed to allow Multiple Table Inheritance for Rails Application. This will give us the previlage to access or assign sub-model attributes from parent model .

Like has_one association has_subclass also follows one_to_one mapping. This method should only be used if the other class contains the foreign key.

Use joins to query through this association.

eg: ParenModel.joins(:child_model).where(child_model: {abc: 'xyz'})


Add this to line gem list and run bundle install

$ gem `mti`

Run this command in terminal

$ rails g mti:install


To create a SubClass run command

$ rails g mti:subclass ChildModel ParentModel

Add has_subclass association to ParentModel

$ has_subclass :child_model


If you are using this gem for the first time please do a migration for our dummy app.

$ cd test/dummy/app/ && rake db:migrate

Once done with the migration go back to the gem root directory then:

$ rake test

That's all! you are ready to go… :)