테이블 : inne을 수행하는 방법에
teacher :id :name
course :id :name
r 레일로이 3 개의 테이블에 가입 하시겠습니까?teachercourse :id :teacher_id :course_id
편집 (내 모델) :
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가 - 내가 조인 결과가 필요합니다 (show 액션) :
class CourseController < ApplicationController def show #not real syntax @course=Course.find(join:teacher,teachercourse,teacher :: where course='javacourse'); end end
이 쿼리에서 얻을 수있는 결과는 무엇입니까? – pkubicki
받기를 원합니다 : 강좌 이름, 교사 이름 – Yosef
정말 '교사 교습'이 필요하지 않으면 ['has_and_belongs_to_many'] (http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_and_belongs_to_many)로 잘 할 수 있습니다. 그 자체로 모델로 – Chowlett