这是我从旧数据库中移动数据的代码:
class Old < ActiveRecord::Base
establish_connection :old_version
self.abstract_class = true
class Recipe < self
set_table_name :recipes
has_many :uploaded_files, :as => :storage
end
class UploadedFile < self
set_table_name :uploaded_files
belongs_to :storage, :polymorphic => true
end
end
当我运行以下代码时
Old::Recipe.all.each do |recipe|
puts recipe.uploaded_files.to_sql
end
它执行这个 SQL
SELECT `uploaded_files`.* FROM `uploaded_files` WHERE `uploaded_files`.`storage_id` = 38 AND `uploaded_files`.`storage_type` = 'Old::Recipe'
问题是我得到:
`storage_type` = 'Old::Recipe'
但是我需要:
`storage_type` = 'Recipe'
如何更改多态关系的类?
的文档has_many
没有给我答案。