azal-io
Joined
Activity
Posted in How do I remove associated records?
I have these associations.
Course
has_many :assignments, class_name: 'CourseManagement::Assignment'
has_many :students, through: :assignments, source: :student
Assignment:
belongs_to :course, class_name: 'CourseManagement::Course'
belongs_to :student, class_name: 'CourseManagement::Student'
Attendance
belongs_to :student, class_name: 'CourseManagement::Student'
belongs_to :session, class_name: 'CourseManagement::Session'
Student:
has_many :assignments, class_name: 'CourseManagement::Assignment'
has_many :courses, through: :assignments, source: :course
has_many :attendances, class_name: 'CourseManagement::Attendance'
has_many :sessions, through: :attendances, source: :session
Session:
belongs_to :course, class_name: 'CourseManagement::Course'
has_many :attendances, class_name: 'CourseManagement::Attendance'
has_many :students, through: :attendances, source: :student
What I want to do.
I have a feature that on Course form, users can select which students are taking the course.
Then when we access that course's session we can select which of these students attended to that session. The issue is when I remove student from the course, I also want that action remove all associated sessions with that student on that session.
So when again we add the student to course we don't see the student on that session.
Thanks