I have a Rails 3 app with the following relationship between models:
Course ---[ 1:n ]---> Module
And when an user enrolls into a Course I have this:
Enrollment ---[ 1:n ]---> ModuleStatus
Each Enrollment also always have an user and a course
QUESTION: How can I enforce that when an Enrollment is created for an user, the system goes ahead and creates a ModuleStatus for each of the modules that the given Course has?
Should I use a callback to enforce this creation?
If so, what callback is suitable here? Would it be after_create?
Thanks!
Short answer: yes, using
after_createcertainly makes sense. It would probably look something like this (obviously you can fill in the details of your modelling).