In general you want associations almost all of the time, if you do not have a particular use case where you know that you want to do something different and know exactly why you are doing it then you almost certainly should model your data relationally. There is on occasion a good reason not to and the hybrid model you get when you use json documents within a relational store means that you can take advantage of other options when required without having to make the same trade offs for your whole data model.
The main benefits you get with the embedded document (not an exhaustive list just a few key ones):
- it can be more flexible, the schema restrictions in this case only exist in your application and not the database, you can store some very loosely structured data if required
- if the embeded document is isolated from other data then you can get even a complex structure back out just by fetching a row
On the other hand, it can be much harder to perform many kinds of queries on embedded data, it doesn’t have relationships so updates usually mean updating the same data in multiple documents, it doesn’t have as much of a structure so you have to do more work to keep that structure sane at the application level and migrations that restructure those embeded documents require a lot more effort.
In the class example quite a bit of the detail that would really make huge amounts of difference in a decision is not really clear. Here are a few things that you could think about:
- Can a student belong to both a Math class and a Physics class?
- Do you frequently need to be able to query information about the students or only query about the class itself?
- Is the student related to any data other than a class?