Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Need help with designing a classroom attendance Model

model database relation sql date object

  • Please log in to reply
4 replies to this topic

#1 jakeed1

jakeed1

    Passenger

  • Members
  • 3 posts

Posted 04 June 2014 - 01:22 AM

Since this is a general question about models / relationships, I figured I'd post here and see what you guys think.

 

I'm building a classroom attendance app, and I need help with some high level theory.

 

I have a Section model and a Student model. 

Section has_many students

Student belongs_to Section

 

Now, I need to create the attendance portion. The idea is that the teacher will take attendance on the day of class (duh). I need help conceptualizing how the Attendance model will work.

 

I want to be able to mark a student present, absent, and late for the current day.

 

How should I go about structuring this?  I'm stumped on how to relate the Attendance to the Student to the date.

 

Is it a new Attendance model? Or some association on the Student model?

 

Any ideas are greatly appreciated.

 

Thanks.



#2 th3mus1cman

th3mus1cman

    Signalman

  • Members
  • 14 posts
  • LocationRichmond, VA

Posted 04 June 2014 - 05:33 PM

There is a few ways you could do this.  One way you could do it is to have a Session model that stores the day and is related to the Section. Then you could do a Student has many Sessions through Attendances.

class Session
  has_many :attendances
  has_many :students, through: :attendances
  belongs_to :section
  attr_accessible :day
end

class Attendance
  attr_accessible :state #[:present, absent, :tardy...]
  belongs_to :student
end

class Student
  has_many :attendances
  has_many :sessions, through: :attendances
end

Rails Developer and Partner at Left + Right


#3 jakeed1

jakeed1

    Passenger

  • Members
  • 3 posts

Posted 05 June 2014 - 03:33 PM

 

There is a few ways you could do this.  One way you could do it is to have a Session model that stores the day and is related to the Section. Then you could do a Student has many Sessions through Attendances.

class Session
  has_many :attendances
  has_many :students, through: :attendances
  belongs_to :section
  attr_accessible :day
end

class Attendance
  attr_accessible :state #[:present, absent, :tardy...]
  belongs_to :student
end

class Student
  has_many :attendances
  has_many :sessions, through: :attendances
end


#4 jakeed1

jakeed1

    Passenger

  • Members
  • 3 posts

Posted 05 June 2014 - 09:06 PM

Awesome. Looks great, thank you. I'll let you know how it goes!   :)



#5 renoldscott

renoldscott

    Passenger

  • Members
  • 6 posts
  • LocationUSA, NY

Posted 10 June 2014 - 08:31 AM

the above code i have used. Thanks for share such great discussion.


From User Interface Design and Coding Services at whitepaperit.com






Also tagged with one or more of these keywords: model, database, relation, sql, date, object

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users