【发布时间】:2011-07-28 22:06:01
【问题描述】:
我有一个 Products 表并想添加一列:
t.references :imageable, :polymorphic => true
我试图为此生成迁移:
$ rails generate migration AddImageableToProducts imageable:references:polymorphic
但我显然做错了。有人可以提出任何建议吗?谢谢
当我在生成迁移后尝试手动放入时,我是这样做的:
class AddImageableToProducts < ActiveRecord::Migration
def self.up
add_column :products, :imageable, :references, :polymorphic => true
end
def self.down
remove_column :products, :imageable
end
end
还是不行
【问题讨论】:
-
不是一个答案,但为了避免混淆,您确定想要这个关于产品的专栏吗? rails 指南甚至有一个 Products 示例,该列在图片上guides.rubyonrails.org/…
-
这很方便:
:references{polymorphic}。例如,rails generate migration AddImageableToProducts imageable:references:{polymorphic}。 Source
标签: ruby-on-rails polymorphic-associations rails-migrations