Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:36:40+00:00 2026-05-23T15:36:40+00:00

Right now my products model has a string column of category, with the form

  • 0

Right now my products model has a string column of category, with the form having a select which gets its values from an array in the product model. Right now there are only three possible categories: wood_stoves, arborist_gear, and chainsaws. I have a controller with an action for each of those that lists the products for their respective category.

I’m switching the categories to a database table and nesting products in it with has_many and belongs_to relationships, and here’s my question. Is the following a bad idea?

  1. Create a record for each of wood_stoves, arborist_gear, and chainsaws.
  2. Create a migration that converts the value of each of those in the products/category column into the corresponding record id integer from the newly created categories records.
  3. Add to the migration a step that changes the category.string column to a category.integer column.
  4. Add to the migration the necessary down steps to revert all that.

In short, should I do all this in a migration so it’s reversible, or should I abandon reversibility and manually make the changes to the database to avoid a somewhat ridiculous looking migration that will only be able to reverse products that correspond to the original categories? In other words, the migration won’t be able to reverse products that belong to newly created categories.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:36:40+00:00Added an answer on May 23, 2026 at 3:36 pm

    Sounds good. The only thing that I would do different is stick with the Rails convention of having a foreign key column name end with “_id”. Life is just easier that way. In your case remove the category column from your products model and add a category_id column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have id values for products that I need store. Right now they are
SELECT PRODUCTS.p_id, model, price, CATEGORIES.category FROM PRODUCTS, CATEGORIES WHERE PRODUCTS.subcat_id = CATEGORIES.category_id AND PRODUCTS.model
Right now, I've just some code which fetches the picture from the URL directly.
Right now, the label for my Activity has the name of the current Activity.
I've a site, we are using ASP.NET 4.0, and right now our products content
Right now in a database I have a Members table and a Products table
Right now I'm working on a project which requires an integer to be converted
Right now, I've got a switch statement which is being used to create objects
I'm building a desktop application right now that presents its human-readable output as XHTML
Right now I have an upload field while uploads files to the server. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.