Been racking my brain for a while, and the problem is this. Let's say you have a superclass Vehicle that can have subclasses like Car, Boat, Horse, etc (or use the generic "Product" superclass for the example). Each subclass will have attributes that only make sense to itself, like "number of wheels" or "horseshoes per mile".
To store this in a relational database, you can use something like STI (http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html), which will leave you with a very sparse table, or CTI (http://martinfowler.com/eaaCatalog/classTableInheritance.html), which is not native rails and can complicate modeling. You can also use EAV (http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model), which most people equate to a slow form of suicide.
Or you can take another option and just serialize the data into a blob field. Not so good if you want to query it (they say postgresql hstore might help, I have no idea about this), potentially great idea if you just want to store and display it later.
Now, my questions (and thanks for reading so far).
- Is a serialized blob a good way to go or should I go ER all the way? If so, which model would be more... sane?
- In any of these cases, how can I then build a form to fill this data out?
- In the serialized model, I need a way to keep a standard fieldset per item (Horse: favorite_hay:<options(green, dry)>, watches_my_little_pony:<boolean>). Is this even viable?
- How can I validate the data (specifically in rails)?
I know this is not a simple thing to reply to but I'd greatly appreciate any help you can provide me.