开发者

Without foreign key in rails

i want to add in my 开发者_运维百科migration field parent_id, but it isn't FK, how i can say it to rails? Thanks, i read about this, but forgot and now can't find it..


I think you can just add it in the same way as any other field:

for example

rails g migration add_parent_id_to_foo parent_id:string

or

class AddParentIdToFoo < ActiveRecord::Migration
  def self.up
    add_column :foos, :parent_id, :string (or integer or whatever)
  end

  def self.down
    remove_column :foos, :parent_id
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜