0

正如标题所说,我们总是对外键使用类型引用吗?

4

1 回答 1

1

不,你不必。

正如 Rails 指南中所述:http: //guides.rubyonrails.org/migrations.html#special-helpers

另一个帮助器称为引用(也可用作belongs_to)。它最简单的形式只是增加了一些可读性。

另一种选择,在迁移中,您可以声明:

t.integer :account_id # where :account_id will hold the id being referenced to for a belongs_to

举个例子。rails 指南示例是这样的:

create_table :products do |t|
  t.references :category
end

但你也可以这样做:

create_table :products do |t|
  t.integer :category_id
end
于 2013-03-09T04:57:06.587 回答