user1687717
user1687717

Reputation: 3475

core data: many-to-many relationship with state

There are two entities in my app: Class and Student, they are many-to-many relationship, like following:enter image description here

My problem is that in my app, there are two status of student in a class: pass and fail. I don't know how to model it to class or student. For example, should I make another Entity to express the status of a student? Or just adding a status attribute to Class entity?

Upvotes: 0

Views: 90

Answers (2)

Pochi
Pochi

Reputation: 13459

I would suggest having a third entity which expresses the status for the student in a specific class. For example a Set of "classStatuses". Since you might need to store other information later, for example grades, credits, assistance records, etc etc.

The final scheme would be something like

Class - Student in a many to many relation.

Student - ClassStatus in a one to many. (Picture is as an array of the classes the student is taking with its respective status)

This way you can search for the students in a class, search for the classes a student is taking, check the status of the class.

Upvotes: 0

Tommy
Tommy

Reputation: 100632

Presumably you can't add an attribute to class because then if 20 students are taking the same class there'll be only one attribute between them?

You'll need to add a separate entity which has a to-one relationship with both a class and a student and which contains the status. And in reciprocal both student and class will have a to-many relationship with statuses.

EDIT: I guess an alternative solution would be to insert the status directly in between your existing relationship. So a class has a set of statuses, and each status has a student.

So relationships would be one to many from class to statuses and many to one from statuses to students. There'd be no explicit relationship between class and student.

Upvotes: 2

Related Questions