D7na
D7na

Reputation: 106

How to implement MTI in ActiveRecord?

For example I have a User model and a table that has fields: Name, Email and Password. There is also a model of Employer that inherits all the User model and should have its own unique fields, such as for example: Company, Phone etc..

How can I realize a Multiple table inheritance?

Upvotes: 0

Views: 1306

Answers (1)

hedgesky
hedgesky

Reputation: 3311

MTI is poorly supported by Rails. There is a gem active_record-acts_as which does the thing.

UPDATE:

I decided to extend my answer after reading your comment about employers/employees. At the moment I'm working on an app where there are also different types of users and instead of storing only :current_user_id in session I've decided to store current_profile_type and current_profile_id, so current_profile could be an instance of different models.

There might be similar functionality for those models; it could be extracted into concern. Different views could be rendered depending on certain class of current_profile.

Maybe this approach could be applied in your situation, too.

Upvotes: 1

Related Questions