我有很多数据试图在 Rails 2.3.8 中植入多态模型。所有数据的关联都与县模型有关。数据如下:
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'},
...
])
:value_type => County 值导致“String:Class 的未定义方法 `base_class'”。
我有数以万计的这些值,我想将它们播种到数据库中。它们与上面的值类似,除了一些与县模型相关,一些与州模型相关,还有一些与城市模型相关。它们是静态值,在播种到数据库后不会被编辑。
如何将模型播种到 :value_type 字段中?
(或者......我是否错误地接近这个,如果是这样,你会如何接近它?)
编辑: schema.rb 文件的相关部分:
艾萨克——
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
我也在播种上尝试了以下方法,但它没有用(引号中的县):
{ :value => '14389', :value_type => 'County', :value_id =>'3103'},