Skip to content
/ mti Public
forked from VishalTaj/mti

Implementing Multiple Table Inheritance(MTI) in Rails

License

Notifications You must be signed in to change notification settings

boyfunky/mti

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mutiple Table Inheritance (MTI)

<img src=“https://badge.fury.io/rb/mti.svg” alt=“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… :)

About

Implementing Multiple Table Inheritance(MTI) in Rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 80.6%
  • HTML 15.3%
  • CSS 2.2%
  • JavaScript 1.9%