Ryan Glover wrote:
Hello,
I am developing an application that will have 100's of model classes each derived from a single source class. Each model will have 4 similar attributes but then have about a dozen unique ones each. I looked into using STI but balked at creating tables with a 1000 columns. I then looked at using inherits_from and creating an new table for each class that holds the new class columns. Problem is, I'll end up with 100's of tables, which also does not appeal to me.
My third solution, the one I am asking advice on, is this.
I create a single table with the 4 common columns and a dozen columns with names such as float1, float2, float3, ... , string1, string2, .. etc. Creating enough columns of each type to cover my largest subclass. Then I use STI and for each class I map the generic columns to the nicer names inside the subclasses. So in one class float1 may be miles/hour while in another class it might be turkeys/hectare.
Does this sound like a reasonable approach?
Also, how would I map the generic names to nice names in my subclasses? (I am a RoR noob)
And of course, does anyone see a much better way to do what I have proposed?
Thank you, Ryan Glover
-- Posted via http://www.ruby-forum.com/.
My guess is that there is a much better way of approaching this. If you have hundreds of different attributes, there is probably a much simpler way of thinking about your data that will vastly simplify things in the long run.
For example, if you have several different attributes denoting a value in 'mph', 'ft/s', 'm/s', etc.. it would be better to store the value as a 'value' attribute and a 'unit' attribute.
A clearer explanation of exactly what you are trying to accomplish would go a long way.
_Kevin