我有2個模特 - 教師和主題。 A想通過名稱資格連接表連接它們。Rails 3 - has_and_belongs_to_many
它看起來像我做錯了什麼:
class Teacher < ActiveRecord::Base
has_and_belongs_to_many :subjects, :join_table => "Qualification"
end
class Subject < ActiveRecord::Base
has_and_belongs_to_many :teachers, :join_table => "Qualification"
end
我的遷移:
class CreateQualificationJoinTable < ActiveRecord::Migration
def change
create_table :qualification, :id => false do |t|
t.integer :subject_id
t.integer :teacher_id
end
add_index :qualification, :subject_id
add_index :qualification, :teacher_id
end
end
,當我打開軌道控制檯和打印,例如
ruby-1.9.3-head :013 > Qualification
我得到這樣的:
NameError: uninitialized constant Qualification
from (irb):13
from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
有什麼問題?
相信你需要一個模式叫資格映射表。 – 2012-03-30 14:11:11
@NekoNova:只有當ExiRe想要對連接表本身做些什麼的時候,否則,讓AR做一些骯髒的工作。請參閱下面的答案以獲取附加鏈接。 – jipiboily 2012-03-30 15:07:47