Question

I am not very experienced in db design, and have not built something like this before, where it involved creating and managing lists, so any advice is much appreciated. Performance can be tuned later on, much more concerned about maintainability and extendability.

I am using Mongodb, and I allow teachers to create their personal educational syllabus that is made up of individual reusable modules. A teacher can in turn customize the syllabus for different students.

###Option 1: Store numerical sequence in the "joint" table:

Syllabus
- has_many SyllabusModuleRecords

SyllabusModuleRecord
- belongs to Syllabus
- belongs to Module
- int Sequence

Module
- has_many SyllabusModuleRecords

s = Syllabus.new
SyllabusModuleRecord.create(:syllabus => s, :module => module1, :sequence =>1 )        
SyllabusModuleRecord.create(:syllabus => s, :module => module2 , :sequence =>2 )
.. and so on

To edit it, I pretty much need to reset all the sequences everytime a modification to the program is made.

###Option 2: Store records with a pointer to a before and after

s = Syllabus.new
s1 = SyllabusModuleRecord.create(:syllabus => s, :module => module1, :before =>nil )        
s2 = SyllabusModuleRecord.create(:syllabus => s, :module => module2 , :before => s1 )

###Option 3: Store module ids as an array inside Syllabus

Syllabus
- array of module_ids

This is obviously the simplest, but I would not be able to store program/module specific information. also, I need to do my own validation checks.

Another consideration is that I would need to allow teachers to in turn customize the syllabus for students too, something like this:

Student
- has_one Syllabus
- has_many SyllabusPersonalizations

SyllabusPersonalizations
- has_one Student
- has_one Syallabus
- .... customization information...
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top