Rails Database Design with Similar models with different attributes -


i designing application has many types of "requests" requests handled in similar nature 1 contain different data.

they each have 1/3 of information same, dates, user information etc.

however different types of requests have different information, , request can have 30 columns in database.

ie.

form date submitted user email provider attribute attribute b attribute c attribute d 

then

form date submitted user email provider attribute e attribute f attribute g attribute h 

i have 40 models in end, don't want have separate tables.

what best way represent this, need full control on layout of show , forms.

i have accomplished using hstore (with postgres) , wondering if there other suggestions.

[edit]

examples of same attributes accross models:

:company_name,:contact_person,:physical_address,:contact_email,:contact_phone 

example of form a:

:mobile_current_provider,:num_mobile_connections,:num_smartphones,:operating_system,:num_high_voice_users 

example of form b

:kw_per_month, :weekend_power, :three_phase_power, :seasonal_difference 

most of fields either strings or integers (with few booleans), can coerced string. of data used displayed, other fields in common used searches , calculations etc

after reading added examples of attributes, impression better off belong other models.

my proposal create 2 more activerecord models: mobileusage , electricityusage

class user < activerecords::base   has_one :mobile_usage   has_one :electricity_usage end  class mobileusage < activerecords::base   belongs_to :user end  class electricity < activerecords::base   belongs_to :user end 

the benefits:

  • better organization. mobile belongs mobile usage, , eletricity belongs electricity usage
  • no null data in user. if put of attributes in 1 model user, users many have mobile info without electricity, , vice versa. leave lots of null data in table.

then, form a, can load attributes of mobile usage in nested form. attributes user saved user , mobile info saved mobile reference. form b similar.

with separation, can allow user fill basic info @ first, details later.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -