Question

I have simple Data mode. Model has 3 tables: teacher,class, teacher_class. Teacher can teach more classes and class can have more teachers.It's classic M:N problem. So, I did third table class_teacher, which represents couple teacher-class. The third class has 2 foreign key (FK) teacher and class. The Data model is here:

https://www.dropbox.com/s/41jr1h713scgxyj/Screenshot%202014-03-03%2021.50.21.png

Please, how can I represent this model in CoreData. In CoreData isn't any FK or PK so, how I can model the relationship? Only with two tables, which have relantionship many to many?? It is possible? Thanks for advice.

Was it helpful?

Solution 2

Yes, create 2 entities and create a bi-directional many to many relationship (create a relationship in each direction and set them as inverse of each other). In this way a Teacher can have a relationship to any number of Classes and vice-versa. You do not need a third entity.

You can add an index in Core Data if you need one, it is added to an attribute of your choice by ticking the indexed option in Xcode.

OTHER TIPS

Didn't follow your link. Also, when asking a question, you should be explicit, and not assume readers know what things like FK and PK mean.

As for your model, you can do it easily enough with a multiway relationship.

In the model GUI, you add a relationship to teacher that references class and you set each side of the relationship to be 'to many'. Thus, each instance of teacher can have multiple class relationships and each instance of class can have multiple teacher relationships.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top