これは私の古いデータベースからデータを移動するための私のコードです:ルビー、has_manyの、ポリモーフィック関係のクラス名を定義
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
のドキュメントは私に答えを与えません。
なぜレシピクラスが古いクラスの中に入れ子になっているのでしょうか? – pixeltrix
おそらく、これはRails Engine @pixeltrixに移されました。誰もがこれに対してより良い答えを持っていますか? – Jwan622