Mohamad El-Husseini
2012-Feb-28 19:09 UTC
Using a string column instead of an id column to differentiate records
How do you decide whether to use a string column or an id column to differentiate between different types of records? Suppose you have a relationships table that maps users to forums. The possible relationships can be: subscriber, moderator, owner. When does it make sense to move those relationship types to their own table and reference them through a relationship_type_id column? What''s the criteria? Or is it better to use a string column to differentiate them? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/t2scvYNus4UJ. 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2012-Feb-28 21:05 UTC
Re: Using a string column instead of an id column to differentiate records
On Feb 28, 2012, at 2:09 PM, Mohamad El-Husseini wrote:> How do you decide whether to use a string column or an id column to differentiate between different types of records? > > Suppose you have a relationships table that maps users to forums. The possible relationships can be: subscriber, moderator, owner. > > When does it make sense to move those relationship types to their own table and reference them through a relationship_type_id column? What''s the criteria? Or is it better to use a string column to differentiate them?Does the client/admin want to be able to change the names or number of these groups, or are you going to be updating it (and thus could make these sorts of code-level changes) when the management winds change? For a few options such as you have here, there''s no reason to do it, IMO, since with an index, it''s going to be just as fast or faster than joining another table by a numerical lookup. I would pull these options out into a constant so you only have one place to type them, too. Walter -- 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 http://groups.google.com/group/rubyonrails-talk?hl=en.