0

變化更新多態關聯Rails中我有三個類圖片,員工和產品定義這樣在型號名稱

Class Picture < ActiveRecord::Base 
    belongs_to :imageable, :polymorphic => true 
end 

class Employee < ActiveRecord::Base 
    has_many :pictures, :as => :imageable 
end 

class Product < ActiveRecord::Base 
    has_many :pictures, :as => :imageable 
end 

我要圖片的型號名稱更改爲圖像。我需要更新多態關聯?

回答

2

首先重命名文件名:從picture.rbimage.rb,類名:從PictureImage和關聯:從has_many :pictureshas_many :images

然後創建一個遷移,改變你的照片的表,這樣的:

class RenamePicturesToImages < ActiveRecord::Migration 
    def change 
    rename_table :pictures, :images 
    end 
end 

最後運行rake db:migrate

+0

謝謝。我會試一試。 – ni8mare