请帮我为下一个需求创建一个正确的迁移
我以前也有过这样的迁移:
class CreateHiringQuestionsAndGroups < ActiveRecord::Migration
def change
create_table :hiring_questions do |t|
t.references :group
t.string :title
t.text :description
t.boolean :is_active, default: true
t.timestamps
end
create_table :hiring_question_groups do |t|
t.references :company
t.string :title
t.boolean :is_active, default: true
t.timestamps
end
end
end应删除的表格:
class Hiring::QuestionGroup < ActiveRecord::Base
belongs_to :company
has_many :questions, class_name: 'Hiring::Question', dependent: :destroy, foreign_key: 'group_id'应更改此表:
class Hiring::Question < ActiveRecord::Base
belongs_to :group, class_name: 'Hiring::QuestionGroup'至:
class Hiring::Question < ActiveRecord::Base
belongs_to :company, class_name: ???我如何通过一次迁移就可以做到这一点?
发布于 2013-12-05 16:54:38
这很简单!
def change
remove_reference :hiring_questions, :group
drop_table :hiring_question_groups
add_reference :hiring_questions, :company
end对不起!)
https://stackoverflow.com/questions/20405196
复制相似问题