On Feb 4, 10:06 pm, Vincent P <ease...@gmail.com> wrote:
> In my app, each user may have one of the 30 predefined occupations.
> Each occupation is a string of about 30 characters.  Should I:
>
>   a.  store this list of occupations in a mysql table and make
> occupation_id a foreign key in the User model?  OR
>   b.  define this list as an array of constants in the User model?
>
> In option b, the array definition will be long and take up space in my
> user.rb file.  Can I put it somewhere else?
>
> I am leaning toward option a because in the future I may want to allow
> each user to have more than one occupations.  In that case, I will
> need to have another table to map the many-to-many relationship
> between users and occupations, right?
>
> In the future, more occupations may be added to the list.  I may also
> try the autocomplete plugin.

Given the possible expansion to many-to-many, and the potential for
more - option A definitely makes more sense. Be aware that it's not
*always* the right way, though: I've got a legacy DB I'm working with
right now that contains DB tables for branches of the US armed forces
(silly, since they are unlikely to change) or even a table like this:

id => name
1 => First
2 => Second
3 => Third

Apparently some Access programmers haven't heard of "helpers"...

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to