I’m working on an upgrade for an existing database that was designed without any of the code to implement the design being considered. Now I’ve hit a brick wall in terms of implementing the database design in code. I’m certain whether its a problem with the design of the database or if I’m simply not seeing the correct solution on how to what needs to be done.
The basic logic stipulates the following:
- Users access the online trainings by way of Seats. Users can have multiple Seats.
- Seats are purchased by companies and have a many-to-many relationship with Products.
- A Product has a many-to-many relationship with Modules.
- A Module has a many-to-many relationship with Lessons.
- Lessons are the end users access for their training.
- To muddy the waters, for one reason or another some Users have multiple Seats that contain the same Products.
- Certification takes place on a per Product basis, not on a per Seat basis.
- Users have a many-to-many relationship with lessons that stores their current status or score for the lesson.
- Users certify for a Product when they complete all of the Lessons in all of the Modules for the Product.
- It is also significant to know when all Lessons for a particular Module are completed by a User.
- Some Seats will be for ReCertification meaning that Users that previously certified for a Product can sign up and take a recertification exam.
- Due to Rule 11, Users can and will have multiple Certification records.
- Edit: When a User completes a Lesson (scores better than 80%) then the User has (according to the current business logic) completed the Lesson for all Products and all Seats that contain the Lesson.
The trouble that I keep running into with the current design and the business logic as I’ve more or less described it is that I can’t find a way to effectively tie whether a user has certified for a particular product and seat vs when they have not. I keep hitting snags trying to establish which Products under which Seats have been certified for the User and which haven’t. Part of the problem is because if they are currently registered for multiple of the same Product under different Seats, then I have to count the Product only once.
Below is a copy of the portion of the schema that’s involved. Any suggestions on how to improve the design or draw the association in code would be appreciated. In case it matters, this site is built on the LAMPP stack.
You can view the relevant portion of the database schema here: http://lpsoftware.com/problem_db_structure.png
What you’re looking for is relational division Not implemented directly in SQL, but it can be done. Search google for other examples.