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'},