mysql - Insert column in existing table -


i'm wondering if there way user on site insert columns in table.

my situation is: admin define table structure each year. admin users insert data table.

e.g. on site this: first table @ later stage, admin add additional column table, keep data intact. table this:

additional table

how can accommodate feature? thinking of creating model lot of hidden fields admin later "unhide" , name, i'm not sure best practice :).

any ideas solve appreciated! (i'm coding in ruby on rails don't think language relevant in case)

oxp1845

i not recommend inserting columns rather use vertical attributes table. e.g.

admin_tables        | id | year or other descriptor want |   1    2015   2    2016   admin_table_columns | id | admin_table_id | named_column |   1         1             name   2         1             description   3         1             info1   4         1             info2    5         2             name    6         2             description   7         2             info1   8         2             info2    9         2             info3  user_inputs  | id | user_id| admin_table_column_id | data |   1      1              1               input name   2      1              2               input description   3      1              4               input info2       .....            

this allow admin add many attributes want "table" out altering existing data or inserting new columns on fly , models defined as:

class admintable < activerecord::base    has_many :admin_table_columns    has_many :user_inputs, through: : :admin_table_columns end   class admintablecolumn < activerecord::base    belongs_to :admin_table    has_many :user_inputs end  class userinput < activerecord::base    belongs_to :admin_table_column    belongs_to :user end 

obviously simplified example think should on right track.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -