小编Tor*_*den的帖子

rails中的t.belongs_to和t.references有什么区别?

t.references和之间有什么区别t.belongs_to?为什么我们有这两个不同的词?在我看来他们做同样的事情?试过一些谷歌搜索,但没有找到解释.

class CreateFoos < ActiveRecord::Migration
  def change
    create_table :foos do |t|
      t.references :bar
      t.belongs_to :baz
      # The two above seems to give similar results
      t.belongs_to :fooable, :polymorphic => true
      # I have not tried polymorphic with t.references
      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-migrations

117
推荐指数
1
解决办法
2万
查看次数

标签 统计

rails-migrations ×1

ruby-on-rails ×1