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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:44:53+00:00 2026-06-02T19:44:53+00:00

I have a situation. I have an old system, and we’re replacing the code

  • 0

I have a situation. I have an old system, and we’re replacing the code to Rails.
So, the table is contract, and in the old system it has about 20 fields but in this new software built in rails, i will use only 5 fields and after some time we will delete all the other fields.

By default, rails maps all the rows of the table thought orm. How can i do to choice the fields that i would like to map under ActiveRecord?

thanks

  • 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-02T19:44:54+00:00Added an answer on June 2, 2026 at 7:44 pm

    I have used a (hacky) solution when using ActiveRecord outside of rails on a database that I didn’t get to create. Basically I dug down into the ActiveRecord code and saw that it leverages a class method ::column_names to facilitate the mapping of fields. Simply not using a field from a model that you intend to remove from the database will work just fine, as others have pointed out. But there is the possibility that the structure of the Db uses a reserved word that will not play nice with ActiveRecord. I added the following code to hide the ‘class’ field from ActiveRecord, because ‘class’ is a reserved name and was raising all sorts of errors.

    private
    def self.column_names
      orig = super
      orig.delete('class')
      return orig
    end
    

    You can of course modify this to remove more than one key from the returned array something like:

    private
    def self.column_names
      orig = super
      ['class', 'field_one', 'field_two'].each do |field_name|
        orig.delete(field_name)
      end
      return orig
    end
    

    Hope this helps,
    /salernost

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

Sidebar

Related Questions

I know it is an old question! But this time I have different situation.
I have a situation where I'm refactoring old code, taking apart an old monster
I have situation like this: Range formulaCells = range.SpecialCells(XlCellType.xlCellTypeFormulas); And I want to iterate
I have situation where i have column in mysql table from which i populate
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation like this: user submits form with action='/pay' in '/pay' I have
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
My situation is this: I have this ViewModel: public class RealtyViewModel { public RealtyViewModel()
I'm having this weird situation : My user's and system's PATH variable is different
I am in this situation: I have to do rounded corners and shadow for

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.