Reputation: 311
I have three classes Picture, Employee and Product defined this way
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
I want to change the Model name of Picture to Image. What all do I need to update regarding the polymorphic associations?
Upvotes: 0
Views: 737
Reputation: 33626
First rename the filename: from picture.rb
to image.rb
, the class name: from Picture
to Image
and the associations: from has_many :pictures
to has_many :images
.
Then create a migration that changes your pictures table, like this:
class RenamePicturesToImages < ActiveRecord::Migration
def change
rename_table :pictures, :images
end
end
Finally run rake db:migrate
.
Upvotes: 2