2

I would like to implement something along the lines of multi table inheritance for my rails application. I am familiar with how STI works and was wondering if the implementation would be similar.

My situation is as follows (names of tables have been changed):

I have a table Employee, and Employee has many janitors and programmers. Janitors and Programmers have many different types of work utensils, so a custodial Table would fit the janitor and Tech table would fit the programmer. Well the jobs could be endless and the attributes for the jobs (janitors, programmers etc) are different so they must be separate tables. I want to consolidate a table called Jobs which belongs under Employee. This table Jobs will have a job_type (here it can be either janitor or programmer) and a utensil_type (custodial, tech). How can I properly implement what this scenario is trying to achieve?

I know how important the type is for STI so I want to know how I can implement this MTI for my rails problem?

Surep
  • 179
  • 4
  • 19
  • I wanted to know what you decided to do for your MTI/STI problem Surep. From most of the articles I've read and the responses on SO, it seems that STI is the way to go if there are only a handful of extra columns on each of the child tables (i.e. Product has name:string, description:text, price:integer, make:string, model:string, Pen has color:string, no:integer, Notebook has pages:integer, lined:boolean). And if there are only a few shared columns between the children models and they each have several to many unique columns, then MTI is the way to go. Would be interested to hear your thoughts – David Routen Jun 19 '15 at 13:29

1 Answers1

1

Maybe ActiveRecord::ActsAs gem will fit your needs https://github.com/hzamani/active_record-acts_as

CV-Gate
  • 1,162
  • 1
  • 10
  • 19