我正在阅读 Rails 指南,发现以下代码行:
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :commenter
t.text :body
t.references :post
t.timestamps
end
add_index :comments, :post_id
end
end
我还阅读了 Michael Hartl 的书 Rails Tutorial,但我没有找到关于上面代码中使用的“t.references”的任何信息。它有什么作用?在Michael 的书中,我在模型中使用了has_many 和belongs_to 关系,而在迁移中没有使用(不是事件t.belongs_to)。