Search code examples
ruby-on-rails-3model-associations

Associations between state and city models


Looking to create a business directory that can be sorted first by state then city (similar to Craigslist).

Should I create a state model and city model separately or created a locations model with both state and city as separate columns in the locations table?


Solution

  • I would go with 2 columns: state and city.

    In order to go something like:

    Collection.order('state ASC') or Collection.order('city ASC')

    Depends after on how complex you want the thing to be.