0

I'm looking to build an application that will allow multiple users to create their own tables, populate those tables with fields and 'contestants'.

I'm trying to piggyback off of the work I did following the rails tutorial (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book) and so am using the user model as created there.

My current thought is to have the following layout:

**User**
- ID
- Name
- Email
- Password
- Created at
- Updated at
- has_many(tables)

**Table**
- ID
- belongs_to (user) through (user.id)
- Title
- Field 1 (string)
- Field 2 (string)
- Field ... (string)
- Field 10 (string)
- has_many(contestants)

**Contestant**
- ID
- belongs_to (table) through (table.id)
- Name
- Field 1 value
- Field 2 value
- Field ... value
- Field 10 value

However, it seems messy that I manually populate (and have to limit) the number of fields and I don't really know how I'm going to account for users that want to create tables with fewer fields.

Also, I'm not sure of the inheritance of the contestant model on the titles (and types) of the field value i.e. sometimes the field will want to be an int, sometimes a string.

Am I going about this the right way or is there a better structure or some Ruby/Railisms that I'm not taking advantage of?

Kali_89
  • 617
  • 2
  • 7
  • 21
  • You will overcomplicate the problem if go try to dynamically create tables. What kind of data are you looking to store in the `Table` model? Have you looked at storing the data as json? You only need fields in tables if you need to perform ad-hoc querying and joins? Is that really what you need? Think about the problem a bit more. – Sahil Muthoo Mar 24 '13 at 17:12
  • Thanks for the response - the structure I'm looking for is that each user has multiple tables that belong to them and so I'd really want all info about the table (inc. contestants, fields and associated values) all stored in that one model. However, I thought that seemed a bit complicated and so added an extra level in. Hadn't really thought about using JSON as I don't really know too much about it. Would that let me create persistent tables as above? If so, have you got any links to good tutorials on that? Cheers! – Kali_89 Mar 24 '13 at 17:52
  • I suggest you take a look into Codd/Database normalization if you haven't already. – thank_you Mar 24 '13 at 23:54

0 Answers0