Foreword: assumptions forthcoming :)
The relationship you are describing is perfect for the JSON document structure. Forget the has_many
and belongs_to
for this scenario. Use JSON's ability to nest objects in a arrays. I would recommend you to quit using a ODM in the short-run while you get your head around MongoDB's expressive documents.
Add the modules
as needed to a nested array on a syllabus. Then, allow the teacher to modify the content for that syllabus only. You would have something like the following for the syllabus:
{
course_id: ObjectId(),
modules: [
{
module_template_id: ObjectId(),
name: "bla bla bla",
description: "bla bla bla",
due_date: "2013-09-28",
modified_from_template: false
},
{
module_template_id: ObjectId(),
name: "bla bla",
description: "bla bla customized",
due_date: "2013-10-05",
modified_from_template: true
}
]
}
You would have another module_templates
collection that is the parent