Aug 31, 2015
Your model is correct.
If you like to retrieve Students you just select Students.
If you like to retrieve Students with Courses then you have two ways to effectively handle this in SPARK.
1) Select Students, then collect their student ids and for those retrieve all Courses. These are 2 SELECT statements using the All method .
2) Write a SQL JOIN operation and retrieve all Students and their Courses in one operation using the Query method. Then iterate over the rows and populate your business objects manually, which should be easy.
Personally, I like method 1 better because I don't have to write SQL.
As an aside: Some ORMs will handle many-to-many automatically for you and they will retrieve Students with Courses. This may seem convenient, but it is anyone's guess how this is implemented. The ORM may not know how to optimize your particular queries. The above methods are super efficient and with SPARK you always know the SQL that executes on the database server.
Hope this helps.