ケース:
テーブル:
teacher :id :name
course :id :name
teachercourse :id :teacher_id :course_id
レールを使用してこの 3 つのテーブルに内部結合するにはどうすればよいですか?
編集(私のモデル):
class Course < ActiveRecord::Base
attr_accessible :name
has_many :teachercourses
has_many :teachers, through: :teachercourse
end
class Teacher < ActiveRecord::Base
attr_accessible :name
has_many :teachercourses
has_many :courses, through: :teachercourse
end
class Teachercourse < ActiveRecord::Base
attr_accessible :course_id, :teacher_id
belongs_to :course
belongs_to :teacher
end
Edit2 - 結合結果が必要な場所 (アクションを表示):
class CourseController < ApplicationController
def show
#not real syntax
@course=Course.find(join:teacher,teachercourse,teacher :: where course='javacourse');
end
end