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
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.
You can of course modify this to remove more than one key from the returned array something like:
Hope this helps,
/salernost