Adding relational data between two entities

Hello, I'm trying to create two classes (database tables) called "Student" and "Course" using the Parse platform. And the intention is to have a relationship between a student and the course. For instance, one student can have many courses. In this case, I'm creating the student "Jeff" with a course "SWEN-500"; then a course "SWEN-500"; and adding the relationship column studentCourse.


However, when I try to create another course for the same student such as

student["course"] = "SWEN-777"

, a different ID for the student (object ID) is created with SWEN-777 as a course. And two students with the same name but different ID's are created with the two courses. But I need to have the same student ID so then I can retrieve one specific student and all his courses he has taken.


func someMethod() {
       
        let student = PFObject(className:"Student")
        student["name"] = "Jeff"
        student["course"] = "SWEN-500"
      
       
        let course = PFObject(className:"Course")
        course["course"] = "SWEN-500"
      
       
        course["studentCourse"] = student
      
        course.saveInBackground()
    }


Any ideas? Thank you in advance.

I don't know the Parse platform, so don't know if this proposal could work.


if you declare student["course"] to be a Set of Strings and not a single String, then you could have several courses for a same student.


        let student = PFObject(className:"Student")
        student["name"] = "Jeff"
        student["course"] = "SWEN-500"


to add a course :

student["course"] = student["course"] + ["SWEN-777"]


By the way, if you add the same course to the set, nothing changes ; that's better than array for this purpose.

Adding relational data between two entities
 
 
Q