我该如何做script/generate migration
为 a 创建一个连接表has_and_belongs_to_many
关系?
该应用程序在 Rails 2.3.2 上运行,但我还安装了 Rails 3.0.3。
Where:
class Teacher < ActiveRecord::Base
has_and_belongs_to_many :students
end
and
class Student < ActiveRecord::Base
has_and_belongs_to_many :teachers
end
对于轨道 4:
rails generate migration CreateJoinTableStudentTeacher student teacher
对于轨道 3:
rails generate migration students_teachers student_id:integer teacher_id:integer
对于导轨
script/generate migration students_teachers student_id:integer teacher_id:integer
(注意表名按字母顺序列出了两个连接表)
然后仅对于 Rails 3 及更低版本,您需要编辑生成的迁移,以便不会创建 id 字段:
create_table :students_teachers, :id => false do |t|
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)