I'll try to summarize the results of my recent search about this issue.
The problem is that we will have different types of content objects (pages, questions, bookmarks..). Although they share basic attributes and behaviors, they have a lot of different attributes and behaviors. Here using ActiveRecord would make some how hard to accomplish this.
- The first way is to use Single Table inheritance. It is only good where you have a couple of models with limited different attributes.
- The second way is to use has_one association. Although it makes the common attributes in a single model (let it be content_properties), the code is going to be ugly, e.g. you'll have to type @page.content_properties.title to access this content. In other words you created has_a relation while you want is_a relationship.
- The third option is to use modules. So imagine you include "act_as_content" module in each content object. The problem is that this allows you to share behavior but not database attributes, except if you find a tricky way to assure that content properties attributes are in the database schema of each model (e.g. using generators). This is quite ugly as well.
- Another choice is use Abstract Active Record. For the first glance it seems good, but we still have the problem of shared attributes that are duplicated in the child classes.
- The last choice is to simulate multi-table inheritance. The code to do this seems a bit ugly but it would give us the result we want. Here's the best link that describes how to do so: http://mediumexposure.com/multiple-table-inheritance-active-record/#mti-the-short-story
So the real solution to the problem is to use multi table choice.
I'm not sure whether existing implementations are safe and stable to use. There is a project that aims to make that easier, which also summarizes existing solutions:
http://peterhamilton.github.com/citier/existing_solutions.htmlI hope this can give you an idea about existing options. I'll try to study the costs and benefits of each ones and update you soon inshalla.
Amjad