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@googlegroups.com.
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.

Search Discussions

  • Walter Lee Davis at Feb 28, 2012 at 9:05 pm

    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 28, '12 at 7:10p
activeFeb 28, '12 at 9:05p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase