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 7865671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:09:34+00:00 2026-06-03T00:09:34+00:00

I need an extra field for custom sorting for my Profile model. So i

  • 0

I need an extra field for custom sorting for my Profile model. So i need to initialize it on column addition.

Now I see two approaches to do that:

  1. Update field after migrations via rake task or at production console.
  2. Write down something like that

    Profile.all.each { |p| p.update_attribute :sorted_at, p.created_at }
    

    in separate migration file.

Is second solution good or bad? And may be is there 3rd solution which is much better than these?

  • 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-06-03T00:09:35+00:00Added an answer on June 3, 2026 at 12:09 am

    My opinion is to update the fields in the migration.

    Pros:

    • That’s what migrations are for (?)
    • No more hassles with tasks. Because one can easily forget to run the task, and in the case of errors or exceptions you have only one place to look at instead of 2.

    Cons:

    • none that i can think of

    Also, it’s a good idea to use update_all instead of looping through each record and updating because of the obvious performance increase.

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

Sidebar

Related Questions

I found that using Smarty with PHP, sometimes extra time will need to be
I have an Address model that contains two float fields, lat and lng .
I need to add some extra field to Joomla registration form without using any
I can add an extra field to the registration. What I need to know
I need to add a foreign key field to an existing django model/postgres table.
I have a page with an ajax filled autocomplete field, if an extra addition
I need to update extra field in associative table with a raw query how
Reading, the Django docs on many-to-many relationships when you need an extra field on
I need to some extra functionalities to a website regarding image handling. The user
I need to add extra validation to my DateField in Admin to make sure

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.