Scenario: I've got a customers table during my application. I additionally have two subclasses of customers, allows say contributing factors and audiences. Each user group should have a completely different group of characteristics however they both share certain user qualities (login, password, title).

What's the easiest method to implement this using Ruby on Rails?

  • I believe single table inheritance could leave me with a lot of null fields.
  • I believe connecting three tables (customers, audiences, contributing factors) works fine, however when attempting to edit any information i must do: @user.viewer, as i would like to have the ability to simply do @viewer.

Any ideas of the greatest solution?

I'd most likely opt for the 3 tables approach. Data integrity rules over code hygiene.

If you wish to allow it to be look neater, put virtual characteristics around the Viewer and Contributor models making it seem like the consumer characteristics are local. You may make it a module and can include it both in Viewer and Contributor models.

You may also setup an :include => :user around the default finders to ensure that you do not get an additional query when utilizing individuals fields.

I am very caffeinated at this time, so comment back in the event that does not seem sensible :)

don't compromise the database schema, allow it to be fit best. I love the 3 table method. Should you choose the database bad, the applying may have very difficult to fix issues later, run slow, etc.