2016-10-24 6 views
-3

나는 사용자 모델을 보유하고 있으며 (교사, 학생 및 원칙) STI학생, 교사, 기간 및 참석자 간의 관계

을 사용하여 모든 클래스에는 많은 학생과 교사가 있습니다. 모든 학생마다 많은 수업이 있습니다. 모든 클래스는 많은 학생들에게 모든 클래스는 많은 기간이

class Class < ApplicationRecord 
    has_and_belongs_to_many:students 
    belongs_to:teacher 
    has_many:periods 
end 

class User < ApplicationRecord 
    has_and_belongs_to_many:students 
    belongs_to:teacher 
    has_many:periods 
end 

class Teacher < User 
    has_many:classes 
end 

class Student < User 
    has_and_belongs_to_many:classes 
    has_many:period 
end 

class Period < ApplicationRecord 
    belongs_to:teacher 
    belongs_to:student 
end 

있습니다.

매 학기마다 각 학생마다 출석이 있기 때문에 수업에 출석을 어떻게 설정할 수 있습니까? 나는 어떻게 사용자와 수업 및 출석과 출석 사이의 관계를 만드나요?

class Attendance < ApplicationRecord 
    ???????? 
end 
+0

질문을 다시 포맷해야합니다. 그것은 당신이 원하는 것을 완전히 명확하지 않습니다. – meshpi

답변

0

교사 1 - * 클래스

클래스 1 - * 학생

클래스 1 - * 기간

학생 1 - * tblStuPer

기간 1 - * tblStuPer

tblStuPer1 - * tblAttendence

,

기간 테이블 :

PeriodID, 일 & 시간, 예컨대 [ '월요일', '오전 9시'], [ '수요일', '오후 3시'].

tblStuPer 테이블 :

tblStuPerID, StudentID, PeriodID.

tblAttendence :

AttendenceID, 날짜, tblStuPer, isHere

이 조인 테이블에 저장하는 것 의미 : 학생 1 ((x)는 월요일 오전 9 periodid),이는 출석율 테이블을 반복하기 때문에 다음 수 실제 날짜, 1990 년 1 월 1 일을 저장하십시오. 그런 다음 클래스 (화학)와 교사 인 Mr E.에 합류 할 수 있습니다.

가장 효과적인 대답은 아니지만 제 생각이 도움이 되길 바랍니다.