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. Thanks, Vincent. -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
I agree, option A is better. Maintaining a hardcoded array of 30 cells is cumbersome and less flexible. -- Posted via ruby-forum.com. -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 4, 10:06 pm, Vincent P <ease...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Thanks all. Now I have the confidence to move forward. On Feb 5, 7:55 am, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 4, 10:06 pm,VincentP <ease...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.