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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:37:58+00:00 2026-05-15T18:37:58+00:00

I have a lot of data that I’m trying to seed into a polymorphic

  • 0

I have a lot of data that I’m trying to seed into a polymorphic model in Rails 2.3.8. The association for all of the data is with the County model. The data looks like:

data = Datum.create([
  ...
  { :value => '14389', :value_type => County, :value_id =>'3103'},
  { :value => '59013', :value_type => County, :value_id =>'3105'},
  { :value => '17117', :value_type => County, :value_id =>'3106'},
  ...
])

The :value_type => County values lead to “undefined method `base_class’ for String:Class.”

I have tens of thousands of these values that I would like to seed into the database. They are similar to the values above except some are associated with the County model, some with the State model, and some with the City model. They are static values that will not be edited after seeding into the database.

How do I seed the model into the :value_type field?

(or… am I approaching this incorrectly and if so, how would you approach it?)

Edit: The relevant part of the schema.rb file:

Isaac –

create_table "data", :force => true do |t|
  t.integer  "value"
  t.string   "value_type"
  t.integer  "value_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

create_table "counties", :force => true do |t|
  t.string   "name"
  t.integer  "state_id"
  t.integer  "ansi_code"
  t.string   "ansi_class"
  t.datetime "created_at"
  t.datetime "updated_at"
end

I tried the following on the seeding, too, and it didn’t work (County in quotes):

{ :value => '14389', :value_type => 'County', :value_id =>'3103'},
  • 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-15T18:37:59+00:00Added an answer on May 15, 2026 at 6:37 pm

    You definitely don’t need the “value” column in your schema — just “value_id” and “value_type”. Then your seed data should look like this:

    ...
    { :value_id => 12345, :value_type => "County" },
    ...
    

    Note that “County” is a string in quotes.

    Another alternative would be to do this:

    { :value => County.find(12345) }
    

    And then Rails will automatically set the :value_type and :value_id columns for you based on the class name and id of the County record. This example might give you a better idea of what’s going on. However, for thousands of records this would be much slower, so the first approach is probably better for this case.

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

Sidebar

Related Questions

I have a query that returns a lot of data into a CSV file.
I have a lot of tab delimited data that is organized into multiple rows
I have a lot of data that is being entered into records with the
In my Rails app, I have a lot of data that is declared as
I have a simple chart (albeit with a lot of data) that renders fine
I have a table with a lot of repeated data that I'd like to
I have a database with a lot of old phpBB data that contains posts
I have a database with a lot of old phpBB data that contains posts
I have a method that returns lot of data, should I use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) for
I have a process that imports a lot of data (950k rows) using inserts

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.