Ruby on Rails Dynamic Models
I'm working on an application where the end user defines what columns a database table should have based off column names in an Excel spreadsheet tha开发者_如何学Got gets uploaded or just by manually defining them before uploading the spreadsheet.
Is this something that AR and MySQL could handle or am I better off using mongodb or couchdb?
In the traditional way, I would basically need a new table each time a user uploaded a document. Am I correct in thinking that with mongodb or couchdb, I would just be defining the document instead of a table?
Thanks!
SQL, in general, has a few methods for handling such dynamic column assignments. MongoDB is definitely a much easier paradigm under which to store this data.
The big limitation here will be "what do you do when the data is in the system?". MongoDB has a built-in map-reduce, but this is obviously completely different from set-based SQL.
So to get more help, you'll probably want to detail what happens once the data is in.
You should checkout PostgreSQL hstore. It stores a key-value field that can be indexed. There is support for ActiveRecord here https://github.com/engageis/activerecord-postgres-hstore, which will allow you to just save a Ruby hash on that field.
精彩评论