Rails迁移:使用替代名称的t.references? [英] Rails migration: t.references with alternative name?

查看:82
本文介绍了Rails迁移:使用替代名称的t.references?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在学校的课程中有一个create_table:

So I have a create_table like this for Courses at a School:

create_table :courses do |t|
  t.string :name
  t.references :course
  t.timestamps
end

但是我希望它引用另外的两门课程,例如:

but I want it to reference two other courses like:

has_many :transferrable_as # A Course
has_many :same_as          # Another Course

我能说以下吗?

t.references :transferrable_as, :as=> :course

推荐答案

我认为此线程具有另一种类似于Rails的方式: 脚手架ActiveRecord:具有相同数据类型的两列

I think this thread has a different more Rails-ish way: Scaffolding ActiveRecord: two columns of the same data type

在迁移中:

t.belongs_to:transferrable_as

t.belongs_to :transferrable_as

t.belongs_to:same_as

t.belongs_to :same_as

这篇关于Rails迁移:使用替代名称的t.references?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆