Question

Let's say you have a many to many relationship between two entities and you use MagicalRecord to manually tie them together.

IE: A Vet has many Pets and a Pet has many Pets

In the code, do you need to add the entity on both sides of the relationship;

ie:

[vet1 addPetObject:cust1Pet1];
[vet1 addPetObject:cust1Pet2];
[vet1 addPetObject:cust1Pet3];
[cust1Pet1 addVetObject:vet1];
[cust1Pet2 addVetObject:vet1];

So, do I need to add the pet object to the vet, and then add the vet to the relevant pet object -- or will Core data / Magical record handle this relationship and tie them on both sides by itself?

Many thanks.

Was it helpful?

Solution

If the relationships are defined as inverse relationships of each other in the Core Data model inspector then you need only set one of them. Core Data will automatically update the inverse relationship. (This is in fact unrelated to MagicalRecord.)

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