I am building a site where users can take various sequences of courses and I am struggling to figure out the schema. So far I have this:
class User
has_many :active_courses
has_many :assigned_lessons, through: :active_courses
end
class Course
has_many :lessons
has_many :active_courses
end
class ActiveCourse
has_many :assigned_lessons
belongs_to :user
belongs_to :course
class AssignedLesson
belongs_to :active_course
belongs_to :lesson
end
class Lesson
has_many :assigned_lessons
end
I fear this is over-complicated. Is there a more simple way to structure an application of this sort? I need the lessons in each course to have a particular order - which can be chosen by the admin when they create a course. And I need to be able to mark active lessons and assigned courses as completed. Any advice much appreciated!
Thanks for your response Ben. Something I am struggling with is how to handle the ordering of lessons in the course. I canāt have an order attribute in my Lesson class because lessons might be in more than one course. Any advice?
Thanks fellas. Soā¦a Course would have one Syllabus, and Syllabus has many Lessons. How would I store the order in Syllabus?
The direction I was going in was to have a CourseLesson join model with an :order attribute on that model. I havenāt managed to figure out how to set the order in my Course#new form though. I tried this:
@pedromoreira, if I take the Syllabus approach, how would you store the order? It seems the simplest approach is to store the meditations ids in a postgres array. But I could just do that in my Course class and dispense with Syllabus, no?
@charliegaines, domain modelling questions are always tricky.
Your CourseLesson approach is the same as Syllabus: the difference being the naming and clarity it adds or not to your domain model. From the information you presented, I would store the order as an attribute in a join model, just as you suggested, since I donāt know enough about your application to say otherwise.
You mentioned you were having problems with that approach in that you arenāt sure how to handle the new Course form. It appears you are making a form that creates the Course and adds in the lessons in order. Maybe you can expose more of your problem with that? It is something that is easier to get help with
@pedromoreira, yes they are tricky - but also interesting! Thanks for your response, I will keep hacking away.
@benorenstein, would you consider doing some weekly iterations or a series of screencasts on the topic? Maybe do it Iron Chef Developer style, have two developers tackle a tricky domain and compare results. I think that would be interesting.