Implementing Multiple Table Inheritance(MTI) in Rails
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib added test cases for save and create Nov 17, 2018
test added test cases for save and create Nov 17, 2018
.gitignore added test cases for save and create Nov 17, 2018
Gemfile added test cases for save and create Nov 17, 2018
Gemfile.lock added test cases for save and create Nov 17, 2018
MIT-LICENSE
README.rdoc added gem version badge Dec 28, 2018
Rakefile Initialized gem Aug 22, 2018
mti.gemspec gem initial updates Aug 22, 2018

README.rdoc

Mutiple Table Inheritance (MTI)

Gem Version

Description

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'})

Installation

Add this to line gem list and run bundle install

$ gem `mti`

Run this command in terminal

$ rails g mti:install

Setup

To create a SubClass run command

$ rails g mti:subclass ChildModel ParentModel

Add has_subclass association to ParentModel

$ has_subclass :child_model

Test

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… :)