-3

i have User model and (teacher, student and principle) inherit from it using STI

every class has many students and one teacher only. every student has many classes. every class has many student

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

every class has many period.

how can i set attendance for class as every period has its own attendance for each student? how i create relationship between user and class and period and attendance?

class Attendance < ApplicationRecord
  ????????
end
Eslam Tahoon
  • 2,205
  • 4
  • 15
  • 21
  • Your question needs to be reformatted. It's not entirely clear what you want. –  Oct 24 '16 at 14:35

1 Answers1

0

Teacher 1 - * Classes

Class 1 - * Students

Class 1 - * Periods

Student 1 - * tblStuPer

Periods 1 - * tblStuPer

tblStuPer 1 - * tblAttendence

Periods table:

PeriodID, Day & time, e.g ['Monday', '9am'], ['Wednesday', '3pm'].

tblStuPer Table:

tblStuPerID, StudentID, PeriodID.

tblAttendence:

AttendenceID, Date, tblStuPer, isHere

This means the join table would store: student 1 in (Monday 9am periodid(x)), because this is repeated an attendence table can then store the actual Date, 01/01/1901. Then from there can join onto Class (Chemistry) and Teacher Mr E.

Not saying it's the most effective answer, but hope my thought process helps.

st3_121
  • 32
  • 6