Reputation: 3447
I know that there is much question about this problem on SO, but none of them was helpful for me. I want to set array of students to each university, but when I fetching all universities - only one them has this array, all others are empty. I have attached small test project, where I had reproduced this problem - https://github.com/sssbohdan/CoreDataProblem.
Upvotes: 0
Views: 90
Reputation: 21536
Your data model seems to have a relationship defined from University to Student, but no inverse relationship from Student to University. You should (almost) always set an inverse relationship. In your case CoreData assumes that each Student is related to only one University. So each iteration through the loop, where you assign Students to a University, they are removed from their previous University.
If you want Students to belong to more than one University, create a to-many inverse for the relationship.
Upvotes: 1