Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 模型名称更改时更新Rails中的多态关联_Ruby On Rails_Database_Ruby On Rails 3_Polymorphic Associations - Fatal编程技术网

Ruby on rails 模型名称更改时更新Rails中的多态关联

Ruby on rails 模型名称更改时更新Rails中的多态关联,ruby-on-rails,database,ruby-on-rails-3,polymorphic-associations,Ruby On Rails,Database,Ruby On Rails 3,Polymorphic Associations,我用这种方式定义了三个类:图片、员工和产品 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

我用这种方式定义了三个类:图片、员工和产品

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
类图片true
结束
类Employee:可成像
结束
类产品:可成像
结束

我想将图片的型号名称更改为图像。关于多态关联,我需要更新什么?

首先将文件名:from
picture.rb
重命名为
image.rb
,类名:from
picture
to
image
,关联:from
has\u many:pictures
重命名为
has\u many:images

然后创建更改图片表的迁移,如下所示:

class RenamePicturesToImages < ActiveRecord::Migration
  def change
    rename_table :pictures, :images
  end
end
类重命名EpictureStoImages

最后运行
rakedb:migrate

谢谢。我要试一试。