STI functionality, but then with multiple tables


I am writing something similar (well, its an app using polymorphism whose objective is to have many different objects be published and search consistently). I'm not saying I have an answer for you, but I can describe my approach. In my case the basic objects are Article which is associated with Story, Map, Gallery and Image. I also have a design goal to be able to add new objects easily.

I've done two things which ease the burden a little:

1. I created a module I mixin to each sub-type object. In this module I have accessor methods for basically all the main object attributes. For example, the module defines article_headline, article_tags, article_author and so on. These now appear as attributes in each sub-type. I order to facilitate publishing i ensure each sub-type has a unique "name" attribute and a "description" attribute. These are the only two assumptions I make but it lets me abstract the publishing model pretty easily.

2. I created a controller called ArticleController which implements the CRUD loop and other common functions. Then I inherit from that controller for the controllers for my objects.

It doesn't solve all problems by any means. But it does mean I can search for Articles by author, name, tags, posting/update dates irrespective of what sub-type. I can invoke a show/edit/new function on any sub-type without knowing its type and get the right behaviour.

And I can add a new object in less than an hour (if its a basic object). I create the model and controller as usual and create the views for show and edit. Add the "require" and "include" for the mixin in the model. Change the inheritance in the controller. All done.

Probably not general interest to the list, so email me as kipcole9 - at- gm-ail dot com if you'd like to continue the conversation - i'd like to find a more elegant solution to this too.

Cheers, --Kip