你好,我要模范喜欢;
class CreateLecturers < ActiveRecord::Migration
def change
create_table :lecturers do |t|
t.string :firstname
t.string :lastname
t.string :position
t.string :email
t.timestamps null: false
end
end
end这是我的第二个模型。
class CreateCurriculums < ActiveRecord::Migration
def change
create_table :curriculums do |t|
t.string :title
t.integer :hours
t.integer :year
t.text :description
t.timestamps null: false
end
end
end我想迁移到课程到讲师。但不是使用id,而是使用标题,这是如何可能的?
所以我使用rails-admin。当我添加一些课程时,我想选择下拉式讲师,当我添加一些讲师时,我想在模型之间选择课程。
发布于 2016-05-16 23:09:23
无论如何,您必须在两个模型之间建立关联。另外,不要忘记在lectures表中添加curriculum_id。
curriculum.rb
has_many :lectureslecture.rb
belongs_to :curriculum添加迁移的
rails g migration add_curriculum_id_to_lectures curriculum_id:integer
https://stackoverflow.com/questions/37256819
复制相似问题